• 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
Re: How do I make one thread wait until another thread exits?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: How do I make one thread wait until another thread exits?


  • Subject: Re: How do I make one thread wait until another thread exits?
  • From: Andrew Farmer <email@hidden>
  • Date: Thu, 12 Feb 2009 03:39:37 -0800

On 12 Feb 09, at 01:25, Oleg Krupnov wrote:
This seems a trivial question for a multi-threading app, but I haven't
been successful in implementing this in Cocoa. I've got deadlocks and
strange logs for seemingly no reason.
<snip>

// the operation object eventually checks the -isCancelled flag and then sends -unlock to the lock, and its thread exits.

This is not an appropriate use of locks, and the runtime error you're getting ("lock unlocked from thread which did not lock it") is a sign of this misuse. Indeed, the design you've described actually contains a subtle synchronization error that could cause deadlock if your code attempts to cancel a thread before it has fully initialized.


As a general point, though, locks are designed for mutual exclusion on shared resources, not inter-thread signalling. Use NSCondition for this sort of communication; alternatively, you may want to investigate pthread_cancel for a more specific solution.
_______________________________________________


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: How do I make one thread wait until another thread exits?
      • From: Oleg Krupnov <email@hidden>
References: 
 >How do I make one thread wait until another thread exits? (From: Oleg Krupnov <email@hidden>)

  • Prev by Date: Reading packets from an audio file
  • Next by Date: Re: How do I make one thread wait until another thread exits?
  • Previous by thread: How do I make one thread wait until another thread exits?
  • Next by thread: Re: How do I make one thread wait until another thread exits?
  • Index(es):
    • Date
    • Thread