Notification handling without run loop of a primary thread
site_archiver@lists.apple.com Delivered-To: Darwin-dev@lists.apple.com 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 (Darwin-dev@lists.apple.com) Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/darwin-dev/site_archiver%40lists.appl... This email sent to site_archiver@lists.apple.com
participants (1)
-
Vladimir Magaziy