Main Page | Report this Page
Linux Forum Index  »  Linux Development - System  »  Can I know when the thread is created/terminated from...
Page 1 of 1    

Can I know when the thread is created/terminated from...

Author Message
Ilho...
Posted: Wed Sep 16, 2009 11:34 am
Guest
Hi everyone,

I would like to know if my shared library can be notified thread
events?
For instance, I would like to know from my shared library if the new
thread is created.
The reason I want to get this event is that I am porting windows dll
program to linux and on Windows dll is notified when the thread is
created/exited so I am looking for something equivalent but I have not
found anything.

Please kindly let me know if there is any way to accomplish this.
Thank you very much in advance.

Ilho <><
 
David Schwartz...
Posted: Wed Sep 16, 2009 11:53 am
Guest
On Sep 16, 2:34 pm, Ilho <yei... at (no spam) gmail.com> wrote:

Quote:
I would like to know if my shared library can be notified thread
events?

This is not UNIX practice.

Quote:
For instance, I would like to know from my shared library if the new
thread is created.
The reason I want to get this event is that I am porting windows dll
program to linux and on Windows dll is notified when the thread is
created/exited so I am looking for something equivalent but I have not
found anything.

Why do you need to know if a thread is created even if that thread
will never call your library?

Quote:
Please kindly let me know if there is any way to accomplish this.
Thank you very much in advance.

Have a 'thread created' function that creates some bit of TSD with
your thread termination function as its destructor. Specify in your
library API that any thread that wishes to interact with your library
must call your 'thread created' function before it does so. To make
things less painful, make your 'thread created' function do nothing if
the TSD already exists.

If you must make it transparent, you can call your 'thread created'
function at possible "first thread entry" points in your library. But
it is, IMO, much better practice to make your library not care about
which threads happen to call it. (Do this if at all possible.)

DS
 
Ilho...
Posted: Thu Sep 17, 2009 3:21 am
Guest
On Sep 16, 5:53 pm, David Schwartz <dav... at (no spam) webmaster.com> wrote:
Quote:
On Sep 16, 2:34 pm, Ilho <yei... at (no spam) gmail.com> wrote:

I would like to know if my shared library can be notified thread
events?

This is not UNIX practice.

For instance, I would like to know from my shared library if the new
thread is created.
The reason I want to get this event is that I am porting windows dll
program to linux and on Windows dll is notified when the thread is
created/exited so I am looking for something equivalent but I have not
found anything.

Why do you need to know if a thread is created even if that thread
will never call your library?

Please kindly let me know if there is any way to accomplish this.
Thank you very much in advance.

Have a 'thread created' function that creates some bit of TSD with
your thread termination function as its destructor. Specify in your
library API that any thread that wishes to interact with your library
must call your 'thread created' function before it does so. To make
things less painful, make your 'thread created' function do nothing if
the TSD already exists.

If you must make it transparent, you can call your 'thread created'
function at possible "first thread entry" points in your library. But
it is, IMO, much better practice to make your library not care about
which threads happen to call it. (Do this if at all possible.)

DS

Thank you very much for your email. I needed to know when the thread
is created because I initialize thread local storage for the later
work. Here is what MSDN says.

The call is made in the context of the new thread. DLLs can use this
opportunity to initialize a TLS slot for the thread.

So that has been pretty convenient for me and thus I was trying to see
if there is anything I can use on Linux. But your suggestion can
probably do what I needed so that should be good enough. Thank you
again and have a good day!

Ilho <><
 
Rainer Weikusat...
Posted: Thu Sep 17, 2009 7:46 am
Guest
Ilho <yeilho at (no spam) gmail.com> writes:
Quote:
On Sep 16, 5:53 pm, David Schwartz <dav... at (no spam) webmaster.com> wrote:
On Sep 16, 2:34 pm, Ilho <yei... at (no spam) gmail.com> wrote:

I would like to know if my shared library can be notified thread
events?

This is not UNIX practice.

For instance, I would like to know from my shared library if the new

[...]

Quote:
Thank you very much for your email. I needed to know when the thread
is created because I initialize thread local storage for the later
work. Here is what MSDN says.

The call is made in the context of the new thread. DLLs can use this
opportunity to initialize a TLS slot for the thread.

This isn't necessary on Linux (actually, it isn't necessary on
Windows, either). Thread local storage is either provided by defining
an object with an (additional) storage class specifier name __thread
or using the POSIX pthread_key_t-based routines. Assuming that you can
use a per-thread pointer, the pointer value will be NULL when it
hasn't yet been initialized. This can be used to determine if
initialization has already happened for a particular thread. The
drawback would be the (slight) runtime overhead for the test, but at
the same time, you get the advantage that this initialization will
only be done for threads which actually call your library, not
'blindly' for every thread.
 
...
Posted: Sat Sep 19, 2009 1:13 am
Guest
On 16 Wrz, 23:34, Ilho <yei... at (no spam) gmail.com> wrote:
Quote:
Hi everyone,

I would like to know if my shared library can be notified thread
events?
For instance, I would like to know from my shared library if the new
thread is created.
The reason I want to get this event is that I am porting windows dll
program to linux and on Windows dll is notified when the thread is
created/exited so I am looking for something equivalent but I have not
found anything.

Please kindly let me know if there is any way to accomplish this.
Thank you very much in advance.

Ilho
 
...
Posted: Sat Sep 19, 2009 1:13 am
Guest
On 17 Wrz, 15:46, Rainer Weikusat <rweiku... at (no spam) mssgmbh.com> wrote:
Quote:
Ilho <yei... at (no spam) gmail.com> writes:
On Sep 16, 5:53 pm, David Schwartz <dav... at (no spam) webmaster.com> wrote:
On Sep 16, 2:34 pm, Ilho <yei... at (no spam) gmail.com> wrote:

I would like to know if my shared library can be notified thread
events?

This is not UNIX practice.

For instance, I would like to know from my shared library if the new

[...]

Thank you very much for your email. I needed to know when the thread
is created because I initialize thread local storage for the later
work. Here is what MSDN says.

The call is made in the context of the new thread. DLLs can use this
opportunity to initialize a TLS slot for the thread.

This isn't necessary on Linux (actually, it isn't necessary on
Windows, either). Thread local storage is either provided by defining
an object with an (additional) storage class specifier name __thread
or using the POSIX pthread_key_t-based routines. Assuming that you can
use a per-thread pointer, the pointer value will be NULL when it
hasn't yet been initialized. This can be used to determine if
initialization has already happened for a particular thread. The
drawback would be the (slight) runtime overhead for the test, but at
the same time, you get the advantage that this initialization will
only be done for threads which actually call your library, not
'blindly' for every thread.
 
 
Page 1 of 1    
All times are GMT - 5 Hours
The time now is Mon Dec 14, 2009 6:28 pm