I have a subclass of NSThread (called MyThread), which runs a RunLoop in main.
When it gets cancelled, it leaves the RunLoop and main will exit.

Some other thread does:

if ( myThread.isCancelled )
{
        //      probably the RunLoop of myThread is no longer running
        //      adding stuff to a non-running RunLoop would result in [myThread 
dealloc] never called (some retain circle)
}
else
{
        [ myThread      performSelector:        @selector(someMethod) 
                                onThread:               myThread
                                withObject:             nil
                                waitUntilDone:  NO 
        ];
}

But what if:
“Some other thread” tests for isCancelled and sees: “not cancelled”
Now yet another thread takes over and cancels myThread.
Then “Some other thread” runs again and does performSelector… (bad)

How to avoid this scenario?

Gerriet.


_______________________________________________

Cocoa-dev mailing list ([email protected])

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [email protected]

Reply via email to