[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: NSThread Comparisons
From: |
Richard Frith-Macdonald |
Subject: |
Re: NSThread Comparisons |
Date: |
Fri, 4 Jan 2008 15:17:00 +0000 |
On 4 Jan 2008, at 00:11, Justin Kendrick wrote:
I'm writing a class which needs to determine the current thread
[NSThread currentThread]
and get an object tied to that thread.
id threadSpecificObject = [[[NSThread currentThread] threadDictionary]
objectForKey: @"KeyForMyObject"];
I'd like to use an NSDictionary keyed by an NSThread object, but
NSThread instances not copyable (and I can't find any good
documentation on how NSDictionary matches non-NSString keys
anyway). Beyond that, I thought that I might use an NSValue created
with valueWithUnretainedObject:, but that feels really hackish.
Not sure why you want to use a dictionary keyed on a thread ... the
above line of code gives you an object stored in the thread dictionary.
Each thread has a dictionary to store thread-local objects, which
seems to be exactly what you need.
For that matter, is there a one-to-one mapping between NSThread
instances and Posix threads -- that is, can I compare two NSThread
pointers and conclude that the NSThread instances do or do not
represent the same thread?
Yes you can compare thread pointers ... each NSThread instance
represents a different thread.