Mailing Lists: Apple Mailing Lists

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

Should getWorkLoop be thread-safe?



Apple's "I/O Kit Fundamentals" guide
http://developer.apple.com/documentation/DeviceDrivers/Conceptual/IOKitFundamentals/index.html
has an example under
   Handling Events > Work Loops > Listing 7-1
of overriding getWorkLoop().  The example tries to make
getWorkLoop() thread-safe.  I have some concerns about the
example code, but does getWorkLoop() really need to be
thread-safe?  I couldn't find any real code that worries about
this.  The code in AppleRAIDSet.cpp in AppleRAID is pretty
typical:
   IOWorkLoop * AppleRAIDSet::getWorkLoop(void)
   {
       // Create a WorkLoop if it has not already been done.
       if (arSetWorkLoop == 0) {
           arSetWorkLoop = IOWorkLoop::workLoop();
       }

       return arSetWorkLoop;
   }

Is there a race condition where two different threads could call
getWorkLoop(), resulting in the unwanted creation of two
different IOWorkLoop objects?
 _______________________________________________
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.