Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 31 Jul 2019 02:27:18 +0000
From:      bugzilla-noreply@freebsd.org
To:        bugs@FreeBSD.org
Subject:   [Bug 239550] std::thread::id uses pthread_equal in undefined ways not handled by _pthread_stubs
Message-ID:  <bug-239550-227@https.bugs.freebsd.org/bugzilla/>

index | next in thread | raw e-mail

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@FreeBSD.org
          Reporter: andrew@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.

help

Want to link to this message? Use this
URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?bug-239550-227>