Proposal: non standard user data hook
Romano Paolo Tenca
rotenca@telvia.it
Mon May 28 19:59:00 GMT 2007
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
More information about the Pthreads-win32
mailing list