Reputation: 43
Now i implement my barrier. but it didn't work well.
When i run barrier time calculate code pthread_barrier_wait consume 180000 us my barrier consume 390000 us
i don't know why and i want to make more fast barrier
Here is my barrier code
82 pthread_mutex_t mutexwait1;
83 int wait_count = NUM_THREADS;
84 int barrier1234(void) {
85
86 int status, cancel, tmp;
87 status = pthread_mutex_lock(&mutexwait1);
88 wait_count = wait_count - 1;
89 if(wait_count == 0){
90 pthread_cond_broadcast(&cond1);
91 wait_count = NUM_THREADS ;
92 }
93 else
94 status = pthread_cond_wait(&cond1, &mutexwait1);
95
96 pthread_mutex_unlock(&mutexwait1);
97 return status;
98
99 }
I find some barrier_wait function but it didn't work. ( download from glibc) => error message(structure variable is not matching) is occur when compile barrier => I wonder this error is caused by version
I am using ubuntu 10.04 Please teach me why my barrier is slow. And how can i implement default pthread_barrier_wait (in my platform)
Upvotes: 0
Views: 1136
Reputation: 58598
glibc's barrier is implemented using lower level primitives, and not a mutex and condition.
Your mutex-based implementation has the obvious problem that it requires every thread which wakes up to re-acquire the mutex only to release it. This goes against the spirit of what a barrier is about: a first class primitive in its own right. (Of course, it's a good way to do a quick and dirty port of code that requires barriers to a platform that provides only mutexes and conditions.)
I wrote the first POSIX barrier functions that existed in glibc some twelve years ago, by the way. Wink!
Upvotes: 2