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

Tema3

parent 2f2efd4f
No related branches found
No related tags found
No related merge requests found
Pipeline #44346 passed
......@@ -108,17 +108,13 @@ 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);
......
No preview for this file type
......@@ -42,13 +42,8 @@ static void process_node(unsigned int idx)
pthread_mutex_unlock(&tp->mutexSuma);
graph->visited[idx] = DONE;
for (unsigned int i = 0; i < graph->nodes[idx]->num_neighbours; ++i) {
pthread_mutex_lock(&tp->mutexCoada);
unsigned int node = graph->visited[graph->nodes[idx]->neighbours[i]];
pthread_mutex_unlock(&tp->mutexCoada);
if (node == NOT_VISITED) {
pthread_mutex_lock(&tp->mutexCoada);
if (graph->visited[graph->nodes[idx]->neighbours[i]] == NOT_VISITED) {
graph->visited[graph->nodes[idx]->neighbours[i]] = PROCESSING;
pthread_mutex_unlock(&tp->mutexCoada);
os_arg_t *arg = malloc(sizeof(*arg));
arg->x = graph->nodes[idx]->neighbours[i];
......
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