Skip to content

Tag: pthreads

Futex and pthreads issue

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 someth…

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 …

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_MON…

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 …

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. C…