• 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 to tell if on main thread
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: How to tell if on main thread


  • Subject: Re: How to tell if on main thread
  • From: Andreas Monitzer <email@hidden>
  • Date: Fri, 18 Jun 2004 19:00:12 +0200

On Jun 18, 2004, at 18:26, Glen Simmons wrote:

How can I tell if I'm currently on the main thread or a secondary thread? I don't need to know if I'm in a specific secondary thread, just that I'm in the main thread or not. I know about NSThread's threadDictionary, and I know I could put a key/value in there, but that seems a little hackish. Thoughts?

Usually, I'm storing the [NSThread currentThread] pointer somewhere statically when I'm sure I'm in the main thread, and later I'm comparing the pointer value to check. For example:

static NSThread *mainThread;

+ (void)initialize {
mainThread=[NSThread currentThread];
}

- (void)someMethod {
if([NSThread currentThread] == mainThread)
blah;
else
blah;
}

andy
_______________________________________________
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.


References: 
 >How to tell if on main thread (From: Glen Simmons <email@hidden>)

  • Prev by Date: Re: How to tell if on main thread
  • Next by Date: Re: How to tell if on main thread
  • Previous by thread: Re: How to tell if on main thread
  • Next by thread: Re: How to tell if on main thread
  • Index(es):
    • Date
    • Thread