Hi all,
I run a barrier program demo and
thread1 does not run printf(…) after pthread_wait().
Here is the source ==>
#include <stdio.h>
#include <time.h>
#include <sync.h>
#include <sys/neutrino.h>
barrier_t barrier;
void* thread1(void *un)
{
time_t now;
time(&now);
printf(“thread1 start at time %s\n”, ctime(&now));
sleep(3);
pthread_barrier_wait(&barrier);
time(&now);
printf(“thread1 done at %s\n”, ctime(&now));
fflush(stdout);
}
void* thread2(void *un)
{
time_t now;
time(&now);
printf(“thread2 start at time %s\n”, ctime(&now));
sleep(6);
pthread_barrier_wait(&barrier);
time(&now);
printf(“thread2 done at %s\n”, ctime(&now));
}
main(int argc, char **argv)
{
time_t now;
pthread_barrier_init(&barrier, NULL, 3);
pthread_create(NULL, NULL, thread1, NULL);
pthread_create(NULL, NULL, thread2, NULL);
time(&now);
printf(“main waiting for barrier at %s\n”, ctime(&now));
pthread_barrier_wait(&barrier);
time(&now);
printf(“barrier in main done at %s\n”, ctime(&now));
and this is what i see ==>
\
./barrier_demo
thread1 start at time Fri May 6 16:36:14 2005
main waiting for barrier at Fri May 6 16:36:14 2005
thread2 start at time Fri May 6 16:36:14 2005
thread2 done at Fri May 6 16:36:20 2005
barrier in main done at Fri May 6 16:36:20 2005
No notification by thread1 appears after phtread_barrier_wait in thread1
Any ideas about why is this happening?
Best Regards
george