Mailing Lists: Apple Mailing Lists

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

Notification handling without run loop of a primary thread



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:
http://lists.apple.com/mailman/options/darwin-dev/email@hidden

This email sent to 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.