• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Threads
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


  • Follow-Ups:
    • Re: Threads
      • From: Alastair Houghton <email@hidden>
    • Re: Threads
      • From: Alastair Houghton <email@hidden>
  • Prev by Date: Re: WKWebView and Mobile Safari and cookie sharing
  • Next by Date: Re: Threads
  • Previous by thread: Re: Mixed-state checkboxes
  • Next by thread: Re: Threads
  • Index(es):
    • Date
    • Thread