• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Fwd: errno global vx. errno pthread...
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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
  • Follow-Ups:
    • Re: Fwd: errno global vx. errno pthread...
      • From: "Michael Andronov" <email@hidden>
References: 
 >errno global vx. errno pthread... (From: "Michael Andronov" <email@hidden>)
 >Re: errno global vx. errno pthread... (From: Patrick Rutkowski <email@hidden>)
 >Re: errno global vx. errno pthread... (From: "Michael Andronov" <email@hidden>)
 >Re: errno global vx. errno pthread... (From: Terry Lambert <email@hidden>)
 >Re: errno global vx. errno pthread... (From: "Michael Andronov" <email@hidden>)
 >Fwd: errno global vx. errno pthread... (From: "Michael Andronov" <email@hidden>)

  • Prev by Date: daemon-child dies on user lougout
  • Next by Date: Re: Fwd: errno global vx. errno pthread...
  • Previous by thread: Fwd: errno global vx. errno pthread...
  • Next by thread: Re: Fwd: errno global vx. errno pthread...
  • Index(es):
    • Date
    • Thread