This is the mail archive of the
pthreads-win32@sourceware.org
mailing list for the pthreas-win32 project.
Proposal: non standard user data hook
- From: Romano Paolo Tenca <rotenca at telvia dot it>
- To: pthreads-win32 at sourceware dot org
- Date: Sun, 27 May 2007 11:06:59 +0200
- Subject: Proposal: non standard user data hook
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