Bug 238650

Summary: pthread_getthreadid_np lacks libc stub
Product: Base System Reporter: Jan Beich <jbeich>
Component: threadsAssignee: Konstantin Belousov <kib>
Status: Closed FIXED    
Severity: Affects Only Me    
Priority: ---    
Version: CURRENT   
Hardware: Any   
OS: Any   

Description Jan Beich freebsd_committer freebsd_triage 2019-06-17 08:47:01 UTC
A consumer may want to avoid -lpthread dependency if thread ID is not critical e.g., only used for tracing/debugging.

Example:
https://github.com/freebsd/freebsd-ports/blob/d1e16f7b264b/multimedia/libva/files/patch-va_va__trace.c

Environment:
  $ cat a.c
  #include <stdio.h>
  #include <pthread_np.h>

  int main()
  {
	  printf("%d\n", pthread_getthreadid_np());
	  return 0;
  }

FreeBSD:

  $ cc a.c
  ld: error: undefined symbol: pthread_getthreadid_np
  >>> referenced by a.c
  >>>               /tmp/a-104ade.o:(main)
  cc: error: linker command failed with exit code 1 (use -v to see invocation)

  $ cc a.c -pthread
  $ ./a.out
  101610

DragonFly:

  $ cc a.c
  $ ./a.out
  0

  $ cc a.c -pthread
  $ ./a.out
  1
Comment 1 commit-hook freebsd_committer freebsd_triage 2019-06-23 10:50:56 UTC
A commit references this bug:

Author: kib
Date: Sun Jun 23 10:50:27 UTC 2019
New revision: 349299
URL: https://svnweb.freebsd.org/changeset/base/349299

Log:
  Add libc stub for pthread_getthreadid_np(3).

  Requested by:	jbeich
  PR:	238650
  Sponsored by:	The FreeBSD Foundation
  MFC after:	1 week

Changes:
  head/lib/libc/gen/Symbol.map
  head/lib/libc/gen/_pthread_stubs.c
  head/lib/libc/include/libc_private.h
  head/lib/libthr/thread/thr_init.c
Comment 2 commit-hook freebsd_committer freebsd_triage 2019-07-03 19:25:54 UTC
A commit references this bug:

Author: kib
Date: Wed Jul  3 19:24:52 UTC 2019
New revision: 349679
URL: https://svnweb.freebsd.org/changeset/base/349679

Log:
  MFC r349299:
  Add libc stub for pthread_getthreadid_np(3).

  PR:	238650

Changes:
_U  stable/12/
  stable/12/lib/libc/gen/Symbol.map
  stable/12/lib/libc/gen/_pthread_stubs.c
  stable/12/lib/libc/include/libc_private.h
  stable/12/lib/libthr/thread/thr_init.c
Comment 3 commit-hook freebsd_committer freebsd_triage 2019-07-03 19:43:13 UTC
A commit references this bug:

Author: kib
Date: Wed Jul  3 19:42:37 UTC 2019
New revision: 349688
URL: https://svnweb.freebsd.org/changeset/base/349688

Log:
  MFC r349299:
  Add libc stub for pthread_getthreadid_np(3).

  PR:	238650

Changes:
_U  stable/11/
  stable/11/lib/libc/gen/Symbol.map
  stable/11/lib/libc/gen/_pthread_stubs.c
  stable/11/lib/libc/include/libc_private.h
  stable/11/lib/libthr/thread/thr_init.c
Comment 4 Mark Linimon freebsd_committer freebsd_triage 2019-07-04 10:46:16 UTC
Committed and MFCed.
Comment 5 commit-hook freebsd_committer freebsd_triage 2019-07-10 01:17:11 UTC
A commit references this bug:

Author: jbeich
Date: Wed Jul 10 01:16:14 UTC 2019
New revision: 506329
URL: https://svnweb.freebsd.org/changeset/ports/506329

Log:
  multimedia/libva: drop -lpthread on FreeBSD 11.4/12.1/13.0

  libva doesn't use threads unless LIBVA_TRACE is passed via environment.

  PR:		238650

Changes:
  head/multimedia/libva/Makefile