I’m testing futexes with pthreads. I’ve written following program: And sometimes it returns 0 as a sum which is proper value but sometimes the returned value of sum is different than 0. My question is why the returned values of “sum” are different than 0? I suspect that there is something wrong with locking but for the moment I cannot
Tag: pthreads
What happens to pthread_key_create() generated keys after a process fork?
From pthread_key_create FreeBSD man page: /comment … The pthread_key_create() function creates a thread-specific data key visible to all threads in the process. Key values provided by pthread_key_create() are opaque objects used to locate thread-specific data. Although the same key value may be used by different threads, the values bound to the key by pthread_setspecific() are maintained on a per-thread basis
Race condition on pthread_kill()?
Linux manual for pthread_kill() has the following paragraph: POSIX.1-2008 recommends that if an implementation detects the use of a thread ID after the end of its lifetime, pthread_kill() should return the error ESRCH. The glibc implementation returns this error in the cases where an invalid thread ID can be detected. But note also that POSIX says that an attempt to
Problem with same thread ID for different threads
I am having trouble with my threads. I am trying to create 10 threads and for each thread I want to print the thread ID. I am able to print the thread ID but the problem is that all threads prints out the same thread ID. This is my code: main: mqClient: When testing two threads this is the output
Can not achieve real time SCHED_FIFO thread within process
Good day everyone ! I am trying to get a 2nd thread (the serial thread) to run as near real time as possible. Within my 2nd spawned serial thread I select() with timeout of 3 mS on a serial port. I also get real time before select() … and then after to get select() delta time. Problem is that sometimes
Measuring Elapsed Time Using clock_gettime(CLOCK_MONOTONIC)
I have to elapse the measuring time during multiple threads. I must get an output like this: Firstly, I used gettimeofday but I saw that there are some negative numbers then I made little research and learn that gettimeofday is not reliable to measure elapsed time. Then I decide to use clock_gettime(CLOCK_MONOTONIC). However, there is a problem. When I use
How to solve pthread_create error (11) resource temporarily unavailable?
I’m building a project in c language (using openwrt as OS) to upload files to FTP server. and i’m using MQTT for the incoming data. So for each topic i subscribe to, i save this data and then upload it to the FTP server and to keep things going smoothly, each time i need to upload a file i just
Why does pthread_exit use void*?
I recently started using posix threads and the choice of argument types in the standard made me curious. I haven’t been able to asnwer the question of why does pthread_exit use void* instead of int for the returning status of the thread? (the same as exit does). The only advantage I see is that it lets the programmers define the
Calling pppd within C program blocks the thread
I have a script which I call from within the C program. I do this before I start the threads as I need the ppp link up before these threads start. I do the below: I tried calling the script within a thread-1 like below: On the success of the script, I get below: After the above, no code beyond
POSIX threads vs parallelism
Do POSIX threads (managing by pthread library) works parallelly? My lecturer has told us that this library creates only user threads, that are not managed by Linux kernel. I wrote some code that fill large matrix and compared times of execution for threads and whole program and it seems to works parallelly. Can I use this library to creating parallel