Re: interprocess communication
Re: interprocess communication
- Subject: Re: interprocess communication
- From: Jonas Maebe <email@hidden>
- Date: Mon, 24 Nov 2008 10:59:02 +0100
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:
This email sent to email@hidden