Discussion:
Why __gthread_active_p() is checked only in few functions?
niXman
2014-09-29 15:41:21 UTC
Permalink
Hi,

I trying to understand why '__gthread_active_p()' is checked only in few
functions, and why exactly in this functions?

For example, '__gthread_active_p()' is used in
'__gthread_mutex_init_function()' but not used for example in
'__gthread_[g|s]etspecific()'? Why?


https://gcc.gnu.org/viewcvs/gcc/trunk/libgcc/gthr-posix.h?view=markup


Thanks.
--
Regards, niXman
___________________________________________________
Dual-target(32 & 64-bit) MinGW-W64 compilers for 32 and 64-bit Windows:
http://sourceforge.net/projects/mingw-w64/
___________________________________________________
Another online IDE: http://liveworkspace.org/
Jonathan Wakely
2014-09-29 16:38:10 UTC
Permalink
Post by niXman
Hi,
I trying to understand why '__gthread_active_p()' is checked only in few
functions, and why exactly in this functions?
For example, '__gthread_active_p()' is used in
'__gthread_mutex_init_function()' but not used for example in
'__gthread_[g|s]etspecific()'? Why?
Some of the functions are short and calling them without active
threads does nothing, so there's no need to check.
__ghtread_mutex_init_function makes several calls, so if they are all
going to do nothing then there's no point calling any of them.
niXman
2014-09-29 19:48:30 UTC
Permalink
Post by Jonathan Wakely
Some of the functions are short and calling them without active
threads does nothing, so there's no need to check.
__ghtread_mutex_init_function makes several calls, so if they are all
going to do nothing then there's no point calling any of them.
What do you mean by "functions are short and calling them without active
threads does nothing"?
--
Regards, niXman
___________________________________________________
Dual-target(32 & 64-bit) MinGW-W64 compilers for 32 and 64-bit Windows:
http://sourceforge.net/projects/mingw-w64/
___________________________________________________
Another online IDE: http://liveworkspace.org/
Jonathan Wakely
2014-09-30 09:22:58 UTC
Permalink
Post by niXman
Post by Jonathan Wakely
Some of the functions are short and calling them without active
threads does nothing, so there's no need to check.
__ghtread_mutex_init_function makes several calls, so if they are all
going to do nothing then there's no point calling any of them.
What do you mean by "functions are short and calling them without active
threads does nothing"?
I mean exactly what I wrote.

__gthread_mutex_lock is a one-line function that forwards to
pthread_mutex_lock. Using GNU libc if you don't link to libpthread.so
then pthread_mutex_lock is a no-op function that does nothing. It is
quicker to just call it than to spend time checking if threads are
active.
niXman
2014-09-30 10:17:10 UTC
Permalink
Post by Jonathan Wakely
I mean exactly what I wrote.
__gthread_mutex_lock is a one-line function that forwards to
pthread_mutex_lock. Using GNU libc if you don't link to libpthread.so
then pthread_mutex_lock is a no-op function that does nothing. It is
quicker to just call it than to spend time checking if threads are
active.
Ok, but what about '__gthread_mutex_init_function()'?


[1]
https://gcc.gnu.org/viewcvs/gcc/trunk/libgcc/gthr-posix.h?view=markup#l729
--
Regards, niXman
___________________________________________________
Dual-target(32 & 64-bit) MinGW-W64 compilers for 32 and 64-bit Windows:
http://sourceforge.net/projects/mingw-w64/
___________________________________________________
Another online IDE: http://liveworkspace.org/
Jonathan Wakely
2014-09-30 10:39:17 UTC
Permalink
Post by niXman
Post by Jonathan Wakely
I mean exactly what I wrote.
__gthread_mutex_lock is a one-line function that forwards to
pthread_mutex_lock. Using GNU libc if you don't link to libpthread.so
then pthread_mutex_lock is a no-op function that does nothing. It is
quicker to just call it than to spend time checking if threads are
active.
Ok, but what about '__gthread_mutex_init_function()'?
What part of my first answer wasn't clear? Do I just need to say the
same thing again using different words?
Jonathan Wakely
2014-09-30 10:40:32 UTC
Permalink
Post by Jonathan Wakely
Post by niXman
Post by Jonathan Wakely
I mean exactly what I wrote.
__gthread_mutex_lock is a one-line function that forwards to
pthread_mutex_lock. Using GNU libc if you don't link to libpthread.so
then pthread_mutex_lock is a no-op function that does nothing. It is
quicker to just call it than to spend time checking if threads are
active.
Ok, but what about '__gthread_mutex_init_function()'?
What part of my first answer wasn't clear? Do I just need to say the
same thing again using different words?
Maybe you can work it out for yourself by seeing if what I wrote about
__gthread_mutex_lock applies.

Is __gthread_mutex_init_function a one-line function that just
forwards to another function?

Loading...