I would like to know can we post more than one thread at a time.
I have code like below
here it does accept and sem_post serially to the thread than invoking all the threads at a time.
#define MAX_MSG_LEN 256
char msg1[MAX_MSG_LEN] = "1";
void *thrdFun1(void *arg);
char argmsg1 = "Thread1: ";
char argmsg2 = "Thread2: ";
char argmsg3 = "Thread3: ";
char argmsg4 = "Thread4: ";
res = sem_init(&sem1,0,0);
res = pthread_create(&thrd1, NULL, thrdFun1, argmsg1);
res = pthread_create(&thrd2, NULL, thrdFun1, argmsg2);
res = pthread_create(&thrd3, NULL, thrdFun1, argmsg3);
res = pthread_create(&thrd4, NULL, thrdFun1, argmsg4);
printf("Enter message to end to thread \n");
return 0; /* writing the comments */
void *thrdFun1(void *arg)
printf("Iam %s message is %s\n",arg,msg1);
Do this kind of behaviour can be achived using posix semaphores ( posting to multiple threads)? or should i use any pthread api like pthread_broadcast etc..
your comments would help in understanding .