[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: NSThread Comparisons
From: |
David Chisnall |
Subject: |
Re: NSThread Comparisons |
Date: |
Fri, 4 Jan 2008 15:05:25 +0000 |
On 4 Jan 2008, at 00:11, Justin Kendrick wrote:
I'm writing a class which needs to determine the current thread and
get an object tied to that thread. 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.
You might consider using the EtoileThread framework (3-clause BSDL).
The ETThread class is a drop-in replacement for NSThread with a few
other features (auto-creation of an autorelease pool and so on). When
a thread is created with an ETThread object, a pointer to that object
is placed into thread-local storage. Calling +currentThread returns
the ETThread object for the current thread, if there is one. Calling -
isCurrentThread lets you know if an ETThread object corresponds to the
current (POSIX) thread.
Have fun.