public inbox for
 help / color / mirror / Atom feed
* Proposal: non standard user data hook
@ 2007-05-28 19:59 Romano Paolo Tenca
  0 siblings, 0 replies; only message in thread
From: Romano Paolo Tenca @ 2007-05-28 19:59 UTC (permalink / raw)
  To: pthreads-win32

I have seen (under windows) many cases where user must associate some 
data to new thread to be used from another thread. Usually pthread id is 
registered in a user array/list of structures with the data needed for 
future access. When the user need that data he will search the array for 
the pthread id: this means allocation, search, destroy, mutex and a lot 
of complexity, bugs and race conditions.

My proposal is a np set of functions to set and get user data:

    void pthread_userdataset_np(ptrhead_t id, void * userdata)
    void * pthread_userdataget_np(ptrhead_t id)

pthread_userdataget_np return NULL if pthread_userdataset_np() was never 
called or the thread has already been destroyed.

Implementation is very simple: add an user slot to ptw32_thread_t structure.
That slot is totally ignored by pthread functions, only when the 
ptw32_thread_t is destroyed the pointer is set to NULL.

Romano Paolo Tenca

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2007-05-27  9:07 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-05-28 19:59 Proposal: non standard user data hook Romano Paolo Tenca

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).