I’m getting a Segmentation Fault when I run this code. Surprisingly, when I set thread_count to 16 or less, it doesn’t give any error. When I debug the code using gdb, the code gets an error at line local_answer += vec_1[j] * vec_2[j]; in the Calculate() thread function. What is the reason for this behavior? How can I fix that?
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
why does pthread_cond_timedwait not trigger after indicated time-limit?
This is supposed to work in a loop (server) and delegate work/inquiry to a faulty library, here represented by the longrun() function call, to a thread with a time-out of tmax=3s. I placed synchronization vars and i am trying to wait for no more than this limit, but when longrun() hangs (run 4), it still waits the full time (7s)
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 is faster than serial in Windows but slower than serial in Linux
I am trying to run the same C++ parallel code to calculated pi with Monte Carlo algorithm on Windows and Linux with the same number of threads (4 threads with 4 CPUs). While the parallel code is faster than the serial implementation on Windows, it is much slower on Linux. Here is the program: output on Windows: on Linux:$g++ -std=c++11
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