Questions tagged [pthread-barriers]

A barrier is a point where the thread is going to wait for other threads and will proceed further only when predefined number of threads reach the same barrier in their respective programs.

32 questions
6
votes
1 answer

How to use pthreads barrier?

Hi Sorry for posting a big dump of code but I'm very new at C code, Basically I'm doing an assignment for college and and I have to implement a "pthread_barrier", now I understand the concept of the barrier (or at least I think I do) But I am just…
Ian
  • 1,490
  • 6
  • 24
  • 39
6
votes
1 answer

unknown type name "pthread_barrier_t"

I am trying to parallelize an algorithm in C. I want to use pthread_barrier_t but my Ubuntu wsl can't find it for some reason. I have pthread.h included and I can use the rest of the pthread functions. libthread.a is installed. #include…
4
votes
2 answers

Ada: behavior like pthread_barrier_wait?

I'm trying to implement a barrier in Ada which has similar functionality to C's pthread_barrier_wait. Ada 2012 has Ada.Synchronous_Barriers but that's not available on my system (gnu-gnat on debian lenny). More specifically, how can I get all…
aquilonis
  • 63
  • 5
3
votes
0 answers

OSX versions with pthread_barrier

Some years ago I wrote some open-source C using POSIX thread barriers, a user on OSX reported a compile failure since these were not implemented on their OS, so we collaborated and ported a primitive implementation into the code, they could then…
jjg
  • 907
  • 8
  • 18
3
votes
2 answers

Implement barrier with pthreads on C

I'm trying to parallelize a merge-sort algorithm. What I'm doing is dividing the input array for each thread, then merging the threads results. The way I'm trying to merge the results is something like this: thread 0 | thread 1…
Artotim
  • 85
  • 5
3
votes
1 answer

Barriers in parallel computing

I was reading about barriers found an example in Wikipedia. I have doubt whether it is correct. Here is the code from ( https://en.wikipedia.org/wiki/Barrier_(computer_science)#Implementation ) struct barrier_type { // how many…
yadhu
  • 1,253
  • 14
  • 25
3
votes
4 answers

What's a good strategy for clean/reliable shutdown of threads that use pthread barriers for synchronization?

I've got a pthread-based multithreaded program that has four threads indefinitely executing this run-loop (pseudocode): while(keepRunning) { pthread_barrier_wait(&g_stage_one_barrier); UpdateThisThreadsStateVariables(); …
Jeremy Friesner
  • 70,199
  • 15
  • 131
  • 234
1
vote
0 answers

operating issues qustions - threads, processes etc. for the above code:

int S1 = 0; int S2 = 0; int x = 0; int run = 1; void Producer(void) { while(run) { while (S1 == S2); x++; __sync_synchronize(); S1 = S2; __sync_synchronize(); } } void Consumer(void) { while(run) { while (S1 !=…
1
vote
1 answer

Do we always need 2 threads for thread barrier to work?

Wanted to check if thread barrier is the right way to go about solving a problem where you have to poll the DB continuously 2-3 times in specific time intervals for incoming events checking for a trigger and then, eventually timeout in a Spring…
1
vote
0 answers

Threads permanently blocking on barrier

I'm working on an assignment which involves the use of various thread synchronizing mechanisms, but the only one that's giving me a headache is pthread_barrier_t. The idea is to implement the barrier as a checkpoint for a few threads, but they are…
0
votes
0 answers

Problem with memory allocation/access using structs and pthread_barriers

In this task i should simulate a simple dice rolling game using only pthread barriers for synchronization. The game is started with n players, specified as a command line argument. Each round all of the players roll a die (generate a random number…
Pur
  • 1
0
votes
1 answer

How to make all threads (pthread) wait till rest of all other threads are running before starting its execution?

The main processes launches 4 threads. Now at this time all 4 threads will start execution immediately, but I want all the threads to wait till rest of all threads are also in running state. I remember using a semaphore to track the thread counts,…
0
votes
1 answer

Why can't my program find the pthread_barrier_init.c file?

For school I am working on a project that has 2 reading threads running and 1 writing thread that work around a shared buffer. This shared buffer is some sort of pointer based list that we programmed ourselves. To make it thread-safe I used to…
Jonas
  • 3
  • 2
0
votes
0 answers

Do we need to use a semaphore if all threads access the same function?

I have a barrier problem task in which N threads have to increment a number X. When all are done incrementing, the last thread will print a message. I understand the need to use semaphores for syncing them to the last thread but why do we need to…
learner
  • 15
  • 3
0
votes
0 answers

Simple openMP barrier has a potential deadlock

I have a simple dissemination barrier implemented in OpenMP that has a potential deadlock and I have not been able to figure out why. The threads share a common data structure flags which looks something like this: // each other. typedef struct…
Anonymous
  • 33
  • 4
1
2 3