diff --git a/A2/fauxgrep-mt b/A2/fauxgrep-mt index b55b683..48e644a 100755 Binary files a/A2/fauxgrep-mt and b/A2/fauxgrep-mt differ diff --git a/A2/fauxgrep-mt.c b/A2/fauxgrep-mt.c index af8270a..7a7fa81 100644 --- a/A2/fauxgrep-mt.c +++ b/A2/fauxgrep-mt.c @@ -88,15 +88,12 @@ int main(int argc, char * const *argv) { paths = &argv[2]; } - //printf("Initializing job queue\n"); job_queue_init(&q, 64); pthread_t threads[num_threads]; for (int i = 0 ; i < num_threads ; i++) { - //printf("Initializing thread %i\n", i); pthread_create(&threads[i], NULL, fauxgrep_thread, strdup(needle)); } - //printf("finished initializing threads\n"); // FTS_LOGICAL = follow symbolic links // FTS_NOCHDIR = do not change the working directory of the process @@ -117,7 +114,6 @@ int main(int argc, char * const *argv) { case FTS_D: break; case FTS_F: - //printf("%s\n", p->fts_accpath); job_queue_push(&q, strdup(p->fts_path)); break; default: @@ -125,12 +121,9 @@ int main(int argc, char * const *argv) { } } - //printf("done pusing jobs\n"); - fts_close(ftsp); job_queue_destroy(&q); - //printf("done destroying jobqueue\n"); for (int i = 0 ; i < num_threads ; i++) { pthread_join(threads[i], NULL); diff --git a/A2/fhistogram b/A2/fhistogram index e3f4ae9..5e1d08b 100755 Binary files a/A2/fhistogram and b/A2/fhistogram differ diff --git a/A2/fhistogram-mt.c b/A2/fhistogram-mt.c index 6dcd041..65debb4 100644 --- a/A2/fhistogram-mt.c +++ b/A2/fhistogram-mt.c @@ -26,15 +26,7 @@ int global_histogram[8] = { 0 }; struct job_queue q; -pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER; -void update_histogram_mt(int local_histogram[8]) { - pthread_mutex_lock(&mutex); - merge_histogram(local_histogram, global_histogram); - print_histogram(global_histogram); - pthread_mutex_unlock(&mutex); - -} int fhistogram_mt(char const *path) { FILE *f = fopen(path, "r"); @@ -105,7 +97,6 @@ int main(int argc, char * const *argv) { pthread_t threads[num_threads]; for (int i = 0 ; i < num_threads ; i++) { - //printf("Initializing thread %i\n", i); pthread_create(&threads[i], NULL, fhistogram_thread, NULL); } @@ -138,7 +129,6 @@ int main(int argc, char * const *argv) { fts_close(ftsp); job_queue_destroy(&q); - //printf("done destroying jobqueue\n"); for (int i = 0 ; i < num_threads ; i++) { pthread_join(threads[i], NULL); diff --git a/A2/job_queue.c b/A2/job_queue.c index e2b1bd1..db44d33 100644 --- a/A2/job_queue.c +++ b/A2/job_queue.c @@ -44,7 +44,7 @@ int job_queue_destroy(struct job_queue *job_queue) { int job_queue_push(struct job_queue *job_queue, void *data) { pthread_mutex_lock(&queue_push); pthread_mutex_lock(&queue_operation); - //printf("push start\n"); + job_queue->jobs[job_queue->size] = data; job_queue->size = job_queue->size + 1; @@ -58,7 +58,7 @@ int job_queue_push(struct job_queue *job_queue, void *data) { pthread_mutex_trylock(&queue_destroy); } - //printf("push end\n"); + pthread_mutex_unlock(&queue_operation); return 0; } @@ -66,15 +66,15 @@ int job_queue_push(struct job_queue *job_queue, void *data) { int job_queue_pop(struct job_queue *job_queue, void **data) { pthread_mutex_lock(&queue_pop); pthread_mutex_lock(&queue_operation); - //printf("pop start\n"); + if (job_queue->jobs == NULL) { - //printf("no more job queue\n"); + pthread_mutex_unlock(&queue_pop); pthread_mutex_unlock(&queue_operation); return -1; } - //printf("job queue\n"); + job_queue->size = job_queue->size - 1; *data = job_queue->jobs[job_queue->size]; @@ -91,7 +91,7 @@ int job_queue_pop(struct job_queue *job_queue, void **data) { pthread_mutex_unlock(&queue_push); } - //printf("pop end\n"); + pthread_mutex_unlock(&queue_operation); return 0; } diff --git a/A2/src.zip b/A2/src.zip new file mode 100644 index 0000000..d40ab08 Binary files /dev/null and b/A2/src.zip differ