Skip to content
Advertisement

Tag: mutex

Why is the pthread_mutex_t struct all zeros in gdb?

What causes pthread_mutex_t struct to be all zeros? Core of a deadlocked ARM test application in a gdb session: Answer pthread_mutex_t is used for all mutex types and some of its members are only used for specific mutex types. owner member is set for at least the following mutex types: PTHREAD_MUTEX_ERRORCHECK_NP PTHREAD_MUTEX_RECURSIVE_NP See glibc implementation of pthread_mutex_trylock for full more

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

Semaphores and Mutex behaviour doubts

Do semaphores and mutexes synchronize both threads and processes, or only threads, or only processes? Edit: my mistake it’s C, not shell. Since I programmed through the shell I mistook it. And one more thing: are communication and synchronization the same? Answer SysV IPC semaphores synchronize between processes. With POSIX semaphores, you can choose via the pshared argument to sem_init(3)

print odd and even numbers using 2 threads using mutex in C

Two threads in the program alternately print even and odd numbers till 100. I have tried this and it worked. Is there a way to access the value of the shared data inside main and terminate the 2 threads when the value reaches 100 Answer There were few errors, in the code I posted earlier, I corrected those mistakes and

Is fopen() a thread safe function in Linux?

If I use fopen() call to open a same file in multi-thread, and write data to the file. Should I use a mutex to ensure the data won’t be disordered? Answer If two threads both open the same file with fopen(), they will each have independent file streams (FILE *) backed by independent file descriptors referring to the same file.

Advertisement