C++ gettid() was not declared in this scope

前端 未结 3 2125
轻奢々
轻奢々 2020-12-28 17:32

A simple program is: I would like to get the thread ID of both of the threads using this gettid function. I do not want to do the sysCall directly. I want to use this funct

3条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-28 17:58

    The man page you refer to can be read online here. It clearly states:

    Note: There is no glibc wrapper for this system call; see NOTES.

    and

    NOTES

    Glibc does not provide a wrapper for this system call; call it using syscall(2).

    The thread ID returned by this call is not the same thing as a POSIX thread ID (i.e., the opaque value returned by pthread_self(3)).

    So you can't. The only way to use this function is through the syscall.

    But you probably shouldn't anyway. You can use pthread_self() (and compare using pthread_equal(t1, t2)) instead. It's possible that boost::thread has its own equivalent too.

提交回复
热议问题