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

modif

parent 13a78a39
No related branches found
No related tags found
No related merge requests found
Pipeline #44354 passed
...@@ -63,11 +63,9 @@ static int queue_is_empty(os_threadpool_t *tp) ...@@ -63,11 +63,9 @@ static int queue_is_empty(os_threadpool_t *tp)
os_task_t *dequeue_task(os_threadpool_t *tp) os_task_t *dequeue_task(os_threadpool_t *tp)
{ {
os_task_t *t = NULL; os_task_t *t;
/* TODO: Dequeue task from the shared task queue. Use synchronization. */ /* TODO: Dequeue task from the shared task queue. Use synchronization. */
if (tp == NULL)
return NULL;
pthread_mutex_lock(&tp->mutexCoada); pthread_mutex_lock(&tp->mutexCoada);
pthread_cond_broadcast(&tp->WakeUp); pthread_cond_broadcast(&tp->WakeUp);
while (queue_is_empty(tp) && !tp->stop) while (queue_is_empty(tp) && !tp->stop)
...@@ -104,8 +102,7 @@ static void *thread_loop_function(void *arg) ...@@ -104,8 +102,7 @@ static void *thread_loop_function(void *arg)
void wait_for_completion(os_threadpool_t *tp) void wait_for_completion(os_threadpool_t *tp)
{ {
/* TODO: Wait for all worker threads. Use synchronization. */ /* TODO: Wait for all worker threads. Use synchronization. */
if (tp == NULL) pthread_mutex_lock(&tp->mutexCoada);
return;
while (tp->verifProcessing()) while (tp->verifProcessing())
pthread_cond_wait(&tp->WakeUp, &tp->mutexCoada); pthread_cond_wait(&tp->WakeUp, &tp->mutexCoada);
tp->stop = 1; tp->stop = 1;
...@@ -113,6 +110,7 @@ void wait_for_completion(os_threadpool_t *tp) ...@@ -113,6 +110,7 @@ void wait_for_completion(os_threadpool_t *tp)
pthread_cond_broadcast(&tp->Wait); pthread_cond_broadcast(&tp->Wait);
pthread_cond_wait(&tp->WakeUp, &tp->mutexCoada); pthread_cond_wait(&tp->WakeUp, &tp->mutexCoada);
} }
pthread_mutex_unlock(&tp->mutexCoada);
/* Join all worker threads. */ /* Join all worker threads. */
for (unsigned int i = 0; i < tp->num_threads; i++) for (unsigned int i = 0; i < tp->num_threads; i++)
pthread_join(tp->threads[i], NULL); pthread_join(tp->threads[i], NULL);
......
File added
File added
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