Does linking an `-lpthread` changes application behaviour? (Linux, Glibc)

后端 未结 1 1426
栀梦
栀梦 2020-12-06 11:35

I have a question: if we have an application, which uses no threads, we can link it in two ways:

1) Link as usual, without -lpthread and -ldl

相关标签:
1条回答
  • 2020-12-06 11:55

    glibc itself contains stub code for many pthread functions. These glibc pthread functions do nothing. However, when the program is linked with libpthread then those stubs are replaced with the real pthread locking functions.

    This is intended for use in libraries that need to be thread safe but do not use threads themselves. These libraries can use pthread locks, but those locks will not actually happen until a program or library that links to libpthread is loaded.

    0 讨论(0)
提交回复
热议问题