Skip to content

Commit 53597df

Browse files
gh-154283: Make threading.get_native_id() unique across processes on DragonFly (GH-154287)
On DragonFly BSD lwp_gettid() is only unique within a process (the main thread is always LWP 1), so combine it with the process id, like Solaris. Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent e81f190 commit 53597df

2 files changed

Lines changed: 4 additions & 2 deletions

File tree

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
On DragonFly BSD, :func:`threading.get_native_id` now returns a value that is
2+
unique across processes, matching the other platforms.

Python/thread_pthread.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -399,8 +399,8 @@ PyThread_get_thread_native_id(void)
399399
lwpid_t native_id;
400400
native_id = _lwp_self();
401401
#elif defined(__DragonFly__)
402-
lwpid_t native_id;
403-
native_id = lwp_gettid();
402+
// lwp_gettid() is only unique within a process, so combine it with the pid.
403+
unsigned long native_id = (unsigned long)getpid() << 32 | lwp_gettid();
404404
#elif defined(__sun__) && SIZEOF_LONG >= 8
405405
unsigned long native_id = (unsigned long)getpid() << 32 | thr_self();
406406
#endif

0 commit comments

Comments
 (0)