• 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: Loosing threads in cocoa
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Loosing threads in cocoa


  • Subject: Re: Loosing threads in cocoa
  • From: Nick Zitzmann <email@hidden>
  • Date: Thu, 8 May 2003 02:51:26 -0700

On Thursday, May 8, 2003, at 02:13 AM, Daniel Aarno wrote:

Display a document window, creates a new NSThread that starts a threaded progress indicator. This new thread forks of a new process (using NSTask), waits for this progress to exit, cleans up, stops the progress indicator and exits.

The problem is that when waiting for the NSTask to exit there are 4 threads running, which could be ok I guess, but when the task has exited there are still 2 threads running, where there should only be one. This makes the application sit and waste about 0.5% of CPU power switching between these threads.

Any pointers?

That looks like correct behavior to me. The thing is, with Cocoa applications, once the application has gone multi-threaded (which happens when either the application or some object used by the application detaches an NSThread), it's really hard (impossible?) to get it back down to a single-threaded state without re-launching. So it's common to have at least one thread that is idle and apparently doing nothing, since you never know when it might be used, or what is using it...

Are you sure that thread is using any CPU time at all? If a program like Top reports that the application is using zero CPU time, then the application is using zero CPU time.

Also do I have to explicitly call [NSThread exit] (which I do now), or is it enough to simply return from the thread function?

It is enough to simply return from the thread function, or that's what the pthread_create() man page suggests.

Nick Zitzmann
AIM/iChat: dragonsdontsleep
Check out my software page: http://dreamless.home.attbi.com/

"Great spirits have always encountered violent opposition from mediocre minds." - Albert Einstein
_______________________________________________
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.
  • Prev by Date: Loosing threads in cocoa
  • Next by Date: Re: NSComboBoxCell and NSTableView
  • Previous by thread: Loosing threads in cocoa
  • Next by thread: Re: Loosing threads in cocoa
  • Index(es):
    • Date
    • Thread