Threads
Threads
- Subject: Threads
- From: "Gerriet M. Denkmann" <email@hidden>
- Date: Mon, 11 Jul 2016 12:35:44 +0700
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@hidden)
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:
This email sent to email@hidden