This is the mail archive of the mailing list for the pthreas-win32 project.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: snap-2004-11-03 breakage

Alexander Terekhov wrote:

Code like (from Ettercap)
pthread_t pid = ec_thread_getpid("golem");
if (pid != 0)

Code it like

 pthread_t tid;
 if (ec_thread_getpid("golem",&tid)

But how does ec_thread_getpid() portably determine if the thread
exists or not?

Don't rely on idiotic pthread_kill() "testing". The standard doesn't preclude the use of pointers for thread IDs (e.g. inside pthread_t structure).

Oops. I should have recognised that because ...

Pointers become indeterminate and
trigger undefined behavior for any nonassignment access once the reference storage gets freed. Conforming implementations are allowed to reclaim/free that referenced storage when detached thread is terminated or joinable thread is terminated and joined. Use of "retired" pthread_t values (e.g. as pthread_kill() argument) after that moment will trigger undefined behavior.

... that's exactly why pthread_t was changed in pthreads-win32.

Every function that takes a thread ID argument has the same problem
as pthread_kill() if pointers are used.



Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]