Skip to content
Snippets Groups Projects
Commit bde35858 authored by oscja033's avatar oscja033
Browse files

...

parent 9aff870b
No related branches found
No related tags found
No related merge requests found
...@@ -23,7 +23,7 @@ int main(int argc, char **argv) ...@@ -23,7 +23,7 @@ int main(int argc, char **argv)
char *lines[16536]; char *lines[16536];
char line[80]; char line[80];
// Fix num lines, num columns, strdup-1 // Fix num lines, num columns, strdup-1
FILE *fin = fopen("bible.txt", "r"); FILE *fin = fopen("bible.txt", "r");
while (!feof(fin)) { while (!feof(fin)) {
getline(line, fin); getline(line, fin);
lines[cur] = (char*) malloc(strlen(line)); lines[cur] = (char*) malloc(strlen(line));
......
...@@ -3,6 +3,9 @@ ...@@ -3,6 +3,9 @@
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
#include <stdlib.h> #include <stdlib.h>
#include <pthread.h>
pthread_mutex_t lock = PTHREAD_MUTEX_INITIALIZER;
typedef struct workitem { typedef struct workitem {
void (*fn)(double *); void (*fn)(double *);
...@@ -19,7 +22,9 @@ static void* launchThread(void *in) ...@@ -19,7 +22,9 @@ static void* launchThread(void *in)
volatile int started = 0; volatile int started = 0;
while (!(started = data->started)); while (!(started = data->started));
while (1) { while (1) {
pthread_mutex_lock(&lock);
n = data->current++; n = data->current++;
pthread_mutex_unlock(&lock);
if (n >= data->len) break; if (n >= data->len) break;
data->fn(&data->data[n]); data->fn(&data->data[n]);
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment