Skip to content

Tag: pthreads

get pthread_t from thread id

I am unable to find a function to convert a thread id (pid_t) into a pthread_t which would allow me to call pthread_cancel() or pthread_kill(). Even if pthreads doesn’t provide one is there a Linux specific function? I don’t think such a function exists but I would be happy to be corrected. Backgr…

pthread_self() doesn’t return a meaningful thread id?

I was running this program on RHEL 5 with gcc4.1.2. Seems the syscall can give the correct thread id(same like process id), but pthread_self doesn’t give meaningful result. Is it because pthread_self is not portable? Answer If you read man pthread_self, which you should: Thread identifiers should be con…

pthread mutex does not work correctly on macOS

Currently I am learning POSIX threads on Linux. The following example is counting how many 3(int) there are in an integer array, which returns a correct answer on CentOS 6.5 but a wrong one on macOS 10.12.4. The answer should be 64 * 1024 * 1024 / 2 = 67,108,864 / 2 = 33,554,432. But the answer on macOS is

VS2017 Linux C++ threads issue

I have been testing the VS2017 Linux C++ with remote debugger on Linux Ubuntu. I have created a few example projects for C++ and everything has been working great until I got to threading examples. I cannot seem to get the threads to compile as I keep getting “undefined reference to `pthread_create’&#82…