diff --git a/debugging/fileutil.cpp b/debugging/fileutil.cpp index f4dcc731bcc869e38495d5b36afd60b2aba20bb9..4914bc8426c3c7f2518d5db05470719c7e55814c 100644 --- a/debugging/fileutil.cpp +++ b/debugging/fileutil.cpp @@ -23,7 +23,7 @@ int main(int argc, char **argv) char *lines[16536]; char line[80]; // Fix num lines, num columns, strdup-1 - FILE *fin = fopen("bible.txt", "r"); + FILE *fin = fopen("bible.txt", "r"); while (!feof(fin)) { getline(line, fin); lines[cur] = (char*) malloc(strlen(line)); diff --git a/debugging/workitems.c b/debugging/workitems.c index 0728aead0cd005a2e4cb6fe084d6e437a441fa79..baa723bde4771ff3b87883dd9d349b1f35fe3221 100644 --- a/debugging/workitems.c +++ b/debugging/workitems.c @@ -3,6 +3,9 @@ #include <stdio.h> #include <string.h> #include <stdlib.h> +#include <pthread.h> + +pthread_mutex_t lock = PTHREAD_MUTEX_INITIALIZER; typedef struct workitem { void (*fn)(double *); @@ -19,7 +22,9 @@ static void* launchThread(void *in) volatile int started = 0; while (!(started = data->started)); while (1) { + pthread_mutex_lock(&lock); n = data->current++; + pthread_mutex_unlock(&lock); if (n >= data->len) break; data->fn(&data->data[n]); }