From bde35858c61e8b26026779c51faadedfd00e4d31 Mon Sep 17 00:00:00 2001 From: oscja033 <oscja033@southfork1-109.ad.liu.se> Date: Wed, 9 Oct 2019 12:07:12 +0200 Subject: [PATCH] ... --- debugging/fileutil.cpp | 2 +- debugging/workitems.c | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/debugging/fileutil.cpp b/debugging/fileutil.cpp index f4dcc73..4914bc8 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 0728aea..baa723b 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]); } -- GitLab