Skip to content
Advertisement

Tag: pthreads

c++ thread_local destructors with pthread destructors

I want to do some work after all C++ thread_local destructors called. This is platform specific – Android, so I have access to pthreads. The question is, when pthread_key_created destructors should be called, before or after C++ thread_local destructors? Or they can be interleaved? I tested On Linux Mint and pthread destructors called after C++ ‘s. Answer bionic/pthread_exit.cpp currently has

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. Background I am well aware that it is

Alternate to setpriority(PRIO_PROCESS, thread_id, priority)

Given – Thread id of a thread. Requirement – Set Linux priority of the thread id. Constraint – Cant use setpriority() I have tried to use below pthread_setschedprio(pthread_t thread, int prio); pthread_setschedparam(pthread_t thread, int policy, const struct sched_param *param); Both the above APIs use pthread_t as an argument. I am not able to construct (typecast) pthread_t from thread id. I

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 considered opaque: any attempt to use a thread ID other than in

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

How many ways will a process be terminated in Linux?

I’m reading Advanced Programming in the Unix Environment 3rd Edn, ยง7.3, Process Termination, the following statement make me confused: There are eight ways for a process to terminate. Normal termination occurs in five ways: Return from main Calling exit Calling _exit or _Exit Return of the last thread from its start routine (Section 11.5) Calling pthread_exit (Section 11.5) from the

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'” error. I know the solution to this is

Advertisement