Notification handling without run loop of a primary thread
Notification handling without run loop of a primary thread
- Subject: Notification handling without run loop of a primary thread
- From: "Vladimir Magaziy" <email@hidden>
- Date: Fri, 2 Dec 2005 23:08:32 +0200
Hi all,
I am trying to handle distributed notifications in a CoreFoundation Tool
that does not run a run loop of its primary thread (actually, it is
the requirement). I can not find any solution that works, so I ask you
about possibility to do in general.
I thought that it is possible to track notifications using a run loop of
a separate thread (see code snippet below), but CFRunLoopRun
function does not run a thread run loop, it simply returns a control
and a thread finishes. I guess that I do not initialize a thread run loop
correctly, so please suggest me the appropriate way to run it and force
to handle notifications.
/*******************************************************/
#include <CoreFoundation/CoreFoundation.h>
#include <pthread.h>
int gFlag = 0;
void gNotificationHandler(CFNotificationCenterRef center, void *observer,
CFStringRef name, const void *object, CFDictionaryRef userInfo)
{
gFlag = 1;
}
void *gThreadRoutine(void *value)
{
CFNotificationCenterRef center = CFNotificationCenterGetDistributedCenter();
CFNotificationCenterAddObserver(center, NULL, gNotificationHandler,
CFSTR("NAME1"), CFSTR("NAME2"), CFNotificationSuspensionBehaviorDeliverImmediately);
CFRunLoopRun();
CFShow(CFSTR("[THREAD] FINISHED"));
return NULL;
}
int main()
{
pthread_t thread = {0};
pthread_create(&thread, NULL, gThreadRoutine, NULL);
while (1 != gInt)
{/* do nothing */
}
return 0;
}
/*******************************************************/
Thanks in advance!
Best regards,
Vladimir Magaziy.
_______________________________________________
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