0

what's the difference between pthread in /lib64/libc.so.6 with /usr/lib64/libpthread.a?

if I using pthread, if I should add -lpthread when linking ?

I noticed that gcc will auto add -llibc when linking, if so, I think there is no need to add -lpthread ! am I right for this understand?

enter image description here

jiafu
  • 6,338
  • 12
  • 49
  • 73

1 Answers1

0

See this SO question: Does linking an `-lpthread` changes application behaviour? (Linux, Glibc)

The pthreads functions in glibc are stubs, provided to make it easier to write code that can operate in threaded or non threaded environments. They do not actually do anything.

If you actually want to use pthreads then you do need to link with -lpthread.

Community
  • 1
  • 1
harmic
  • 28,606
  • 5
  • 67
  • 91
  • but why getpid() and pthread_self() can return right value if the pthread in glibc only provide stubs? – jiafu Jan 06 '14 at 09:48
  • but why getpid() and pthread_self() without added link -lpthread can return right value if the pthread in glibc only provide stubs – jiafu Jan 06 '14 at 09:49
  • 1
    The stubs are written to return values meaningful in a non threaded environment. However if you tried to eg. Create a thread, you would find that you cannot. More info here http://www.ohloh.net/p/libpthread-stubs – harmic Jan 06 '14 at 09:53
  • is it weak reference? – jiafu Jan 13 '14 at 12:12
  • @jiafu - yes they are weak symbols, otherwise you would not be able to link the real pthread lib – harmic Jan 13 '14 at 20:25
  • Sorry - have to correct myself. The main factor is symbol interposition. See my answer to your other question: http://stackoverflow.com/a/21103255/1411457 – harmic Jan 13 '14 at 23:14