Skip to content
Snippets Groups Projects
Commit 9c748586 authored by Alexandru BRĂSLAŞU's avatar Alexandru BRĂSLAŞU
Browse files

Tema

parent 54f2dab2
No related branches found
No related tags found
No related merge requests found
Pipeline #44265 canceled
......@@ -70,8 +70,10 @@ os_task_t *dequeue_task(os_threadpool_t *tp)
return NULL;
pthread_mutex_lock(&tp->mutexCoada);
pthread_cond_broadcast(&tp->WakeUp);
while (queue_is_empty(tp) && !tp->stop)
while (queue_is_empty(tp) && !tp->stop) {
pthread_cond_wait(&tp->Wait, &tp->mutexCoada);
pthread_cond_broadcast(&tp->WakeUp);
}
if (tp->stop) {
pthread_mutex_unlock(&tp->mutexCoada);
return NULL;
......@@ -108,13 +110,17 @@ void wait_for_completion(os_threadpool_t *tp)
/* TODO: Wait for all worker threads. Use synchronization. */
if (tp == NULL)
return;
pthread_mutex_lock(&tp->mutexCoada);
while (tp->verifProcessing())
pthread_cond_wait(&tp->WakeUp, &tp->mutexCoada);
tp->stop = 1;
pthread_mutex_unlock(&tp->mutexCoada);
pthread_mutex_lock(&tp->mutexCoada);
while (tp->threadsOut < tp->num_threads) {
pthread_cond_broadcast(&tp->Wait);
pthread_cond_wait(&tp->WakeUp, &tp->mutexCoada);
}
pthread_mutex_unlock(&tp->mutexCoada);
/* Join all worker threads. */
for (unsigned int i = 0; i < tp->num_threads; i++)
pthread_join(tp->threads[i], NULL);
......
......@@ -39,7 +39,7 @@ static void process_node(unsigned int idx)
/* TODO: Implement thread-pool based processing of graph. */
pthread_mutex_lock(&tp->mutexSuma);
sum += graph->nodes[idx]->info;
pthread_mutex_unlock(&tp->mutexSuma);
pthread_mutex_lock(&tp->mutexSuma);
graph->visited[idx] = DONE;
for (unsigned int i = 0; i < graph->nodes[idx]->num_neighbours; ++i) {
if (graph->visited[graph->nodes[idx]->neighbours[i]] == NOT_VISITED) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment