[Bug 239550] std::thread::id uses pthread_equal in undefined ways not handled by _pthread_stubs

bugzilla-noreply at freebsd.org bugzilla-noreply at freebsd.org
Wed Jul 31 02:27:19 UTC 2019


https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=239550

            Bug ID: 239550
           Summary: std::thread::id uses pthread_equal in undefined ways
                    not handled by _pthread_stubs
           Product: Base System
           Version: CURRENT
          Hardware: Any
                OS: Any
            Status: New
          Severity: Affects Many People
          Priority: ---
         Component: bin
          Assignee: bugs at FreeBSD.org
          Reporter: andrew at tao11.riddles.org.uk

Created attachment 206172
  --> https://bugs.freebsd.org/bugzilla/attachment.cgi?id=206172&action=edit
testcase (c++)

std::thread::id defines a distinguished "not equal to any actual thread" value
(the implementation uses 0).

But it feels entitled to pass this value to pthread_equal, whose own spec has
no such distinguished value. (Per the pthread spec this gives an undefined
result.)

If libthr is linked in, this isn't a problem because 0 doesn't actually compare
equal to any thread. But the _pthread_stubs implementation of pthread_equal
returns true unconditionally, which is valid by the pthread spec (since there
is no distinguished pthread_t value).

The attached test program demonstrates the failure; it runs successfully if
linked with -pthread, asserts out if not.

The simplest fix would be to do an actual comparison in the stub version of
pthread_equal. A more correct fix would be for std::thread::id not to assume it
can pass its 0 value to pthread_equal, but I think this would be unnecessary
overhead.

-- 
You are receiving this mail because:
You are the assignee for the bug.


More information about the freebsd-bugs mailing list