Re: Fwd: errno global vx. errno pthread...
Re: Fwd: errno global vx. errno pthread...
- Subject: Re: Fwd: errno global vx. errno pthread...
- From: Jan Brittenson <email@hidden>
- Date: Tue, 07 Oct 2008 12:04:12 -0700
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;
static void * thread2( void * param)
{
bool run(true);
while(run)
{
//Expected behavior:
--- 7,20 ----
#include <errno.h>
#include <aio.h>
! sem_t* sem = NULL;
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;
! sem_init(&sem,0,0);
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;
! 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 (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden