Re: Fwd: errno global vx. errno pthread...
site_archiver@lists.apple.com Delivered-To: darwin-dev@lists.apple.com User-agent: Thunderbird 2.0.0.17 (Macintosh/20080914) What's sem_init()? It has no man page. It'll work if you use sem_open() instead: *** main.cpp~ 2008-10-07 11:54:49.000000000 -0700 --- main.cpp 2008-10-07 11:57:21.000000000 -0700 *************** *** 7,18 **** #include <errno.h> #include <aio.h> ! sem_t sem; ! sem_t* sem = NULL; ! sem_init(&sem,0,0); ! sem = sem_open("iamasemaphore, O_CREAT); ! assert(sem); if( pthread_create(&th2, NULL, thread2, NULL) < 0 ){ std::cout << "Failed to create a second thread\n"; _______________________________________________ Do not post admin requests to the list. They will be ignored. Darwin-dev mailing list (Darwin-dev@lists.apple.com) Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/darwin-dev/site_archiver%40lists.appl... static void * thread2( void * param) { bool run(true); while(run) { //Expected behavior: --- 7,20 ---- #include <errno.h> #include <aio.h> static void * thread2( void * param) { bool run(true); + assert(sem); + while(run) { //Expected behavior: *************** *** 22,28 **** // //However, for unknown reason, the semaphore will be waked-up here with errno==9 //After the first wake-up, it will be return immediately with errno==9 ! if(sem_wait(&sem)<0) std::cout << "Waked-up, with errno=" << (int)errno << "\n" ; } return 0; --- 24,30 ---- // //However, for unknown reason, the semaphore will be waked-up here with errno==9 //After the first wake-up, it will be return immediately with errno==9 ! if(sem_wait(sem)<0) std::cout << "Waked-up, with errno=" << (int)errno << "\n" ; } return 0; *************** *** 34,40 **** int main (int argc, char * const argv[]) { pthread_t th2; if( pthread_create(&th2, NULL, thread2, NULL) < 0 ){ std::cout << "Failed to create a second thread\n"; --- 36,43 ---- int main (int argc, char * const argv[]) { pthread_t th2; This email sent to site_archiver@lists.apple.com
participants (1)
-
Jan Brittenson