FreeBSD's stdio.h has an extern declaration of variable '__isthreaded'. This variable is zero until a process has created a thread. It is used to avoid calling locking functions in libc when they are not required.

But this is not a portable way of checking presence of thread. Linux does not support this. Do we have any equivalent Variable or API in Linux? I am trying to port some code from FreeBSD to Linux.

Thanks in advance for your help.

有帮助吗?

解决方案

What glibc does to provide almost the same feature is to define stub functions for most of the pthread library in glibc. These calls do nothing and are very fast.

Once libpthread.so is linked in, its symbols override the weak glibc symbols and then the real functions are called.

So include pthread and call the locking functions, but don't link with it.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top