• 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: Termination of threads.
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Termination of threads.


  • Subject: Re: Termination of threads.
  • From: Mike Shields <email@hidden>
  • Date: Fri, 8 Feb 2002 16:35:15 -0700

On Friday, February 8, 2002, at 02:08 PM, email@hidden wrote:

Hello, everybody.

I want to be able to terminate Threads within my application. Cocoa seems to define only one function that will be able to do what I want, namely the [NSThread exit]. However, while looking at the docs I saw the plus. Ooops. Things seem more complicated than that...

As far as I get it, I need to set up a proxy object from the callee thread (my UI interface) to the thread that has to be terminated. Then, I invoke a function through the proxy and the thread receives the message and terminates itself.

Question 1: Will this work?
Question 2: Is there a better/quicker/more elegant way of doing this? I hate Cocoa's complicated inter-thread communication system.

Thank you very much for any input.

Nick

Yup, that's basically the way to do it.

I can say that for something like this, a full DO implementation isn't needed. If you already have that, then that's fine, use it. But if you need to fire off a thread to do come computation and don't need it to update the UI directly, then not using DO works just as well (you'd just use NSLocks to synchronize).

The problem with calling +exit (or if there was one -exit) is that those calls stop the thread right then and there. No cleanup, nothing else is called - so if you have resources allocated, they just got leaked. Pthreads has pthread_cancel/pthread_testcancel which helps with this, but there are still issues with system calls that can be cancelled, etc. In my threads programming, I've found it easier and less complicated to have my own cancel/abort/stop strategy worked out specific to that thread and what it's doing.

Mike
----
Mike Shields <mailto:email@hidden>
CD Monkey
Apple Computer, Inc.
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.

  • Follow-Ups:
    • Re: Termination of threads.
      • From: email@hidden
References: 
 >Termination of threads. (From: email@hidden)

  • Prev by Date: Switching NSViews 2
  • Next by Date: Re: Random crashes
  • Previous by thread: Termination of threads.
  • Next by thread: Re: Termination of threads.
  • Index(es):
    • Date
    • Thread