Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: interprocess communication




On 24 Nov 2008, at 04:28, Rakesh Singhal wrote:

pthread_cond_signal() leaves the object nonsignaled like PulseEvent()
in Win32. Is there any POSIX or Mac function which leaves the object
signaled like SetEvent() in Win32? Counting semaphore will not fit in
my case.

There is none in the pthread_* family at least. But you can implement one on top of them using something like this (typed in Mail):


typedef struct _persistent_event
{
  pthread_cond_t cond;
  pthread_mutex_t mutex;
  int isset;
} t_persistent_event;


t_persistent_event *NewEvent(void) { t_persistent_event *event = malloc(sizeof(*event)); pthread_cond_init(&event->condvar, NULL); pthread_mutex_init(&event->mutex, NULL); event->isset=0; return event; }


void SetEvent(t_persistent_event *event) { pthread_mutex_lock(&event->mutex); event->isset=1; pthread_cond_signal(&event->cond); pthread_mutex_unlock(&event->mutex); }


void WaitEvent(t_persistent_event *event) { pthread_mutex_lock(&event->mutex); while (!event->isset) pthread_cond_wait(&event->condvar,&event->mutex); event->isset=0; pthread_mutex_unlock(&event->mutex); }


ResetEvent() and DestroyEvent() left as an exercise to the reader.


Jonas _______________________________________________ Do not post admin requests to the list. They will be ignored. Darwin-dev mailing list (email@hidden) Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/darwin-dev/email@hidden

This email sent to email@hidden
References: 
 >interprocess communication (From: "Rakesh Singhal" <email@hidden>)
 >Re: interprocess communication (From: Jean-Daniel Dupas <email@hidden>)
 >Re: interprocess communication (From: Terry Lambert <email@hidden>)
 >Re: interprocess communication (From: "Rakesh Singhal" <email@hidden>)
 >Re: interprocess communication (From: Terry Lambert <email@hidden>)
 >Re: interprocess communication (From: "Rakesh Singhal" <email@hidden>)



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.