OK, so it seems like making it a platform-dependent value (i.e., it's
an Or_error that might or might not be there) and put our Linux
implementation in there with an IFDEF, seems about right. Others can
presumably contribute other implementations if that has value.
y
On Fri, Aug 29, 2014 at 10:05 AM, Kenneth Westerback
<
kwest...@gmail.com> wrote:
> On 28 August 2014 07:52, Mark Shinwell <
mshi...@janestreet.com> wrote:
>> [gettid] doesn't return the same thing as [pthread_self], though. The
>> latter returns an opaque handle used by the pthreads library; the
>> former returns the numeric thread ID. The purpose of the
>> [Core_extended] function seems almost certainly to be for retrieval of
>> the numeric ID, e.g. for correlation with the output of "top".
>>
>> How is the numeric thread ID obtained on a BSD system?
>>
>> Mark
>
> IANAE, but google says there is no "BSD" mechanism, just a bunch of
> different implementations. e.g. WINE has or had
>
> 1303 /***********************************************************************
> 1304 * get_unix_tid
> 1305 *
> 1306 * Retrieve the Unix tid to use on the server side for the current thread.
> 1307 */
> 1308 static int get_unix_tid(void)
> 1309 {
> 1310 int ret = -1;
> 1311 #ifdef HAVE_PTHREAD_GETTHREADID_NP
> 1312 ret = pthread_getthreadid_np();
> 1313 #elif defined(linux)
> 1314 ret = syscall( __NR_gettid );
> 1315 #elif defined(__sun)
> 1316 ret = pthread_self();
> 1317 #elif defined(__APPLE__)
> 1318 ret = mach_thread_self();
> 1319 mach_port_deallocate(mach_task_self(), ret);
> 1320 #elif defined(__NetBSD__)
> 1321 ret = _lwp_self();
> 1322 #elif defined(__FreeBSD__)
> 1323 long lwpid;
> 1324 thr_self( &lwpid );
> 1325 ret = lwpid;
> 1326 #elif defined(__DragonFly__)
> 1327 ret = lwp_gettid();
> 1328 #endif
> 1329 return ret;
> 1330 }
> 1331
>
> OpenBSD does not have pthread_getthreadid_np() as far as I can grep.
> For linux compat OpenBSD uses
>
> linux_pid_t
> linux_sys_gettid(struct proc *p, void *v, register_t *retval)
> {
> *retval = p->p_pid + THREAD_PID_OFFSET;
> return (0);
> }
>
> where THREAD_PID_OFFSET is currently defined in sys/proc.h as
>
> #define THREAD_PID_OFFSET 1000000
>
> Not sure how helpful all that is. :-). I guess partly it depends on
> what one expects to be able to do with the tid. Just display it? use
> it for debugging info? somehow influence the process/thread?
>
> .... Ken