Skip to content
Advertisement

Tag: pthreads

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

Sending signal to pthread to abort sleeping

I’m have a pthread function, which sleeps most of the time using usleep() I would like to send a signal from the main process to the thread to interrupt the sleeping sometimes. The problem is that I can’t find any reference of which signal exactly to send using pthread_kill() the usleep() man page, states that SIGALRM should not be used

Mutex lock threads

Am new to multi threaded/processs programming. So here’s what I need to clarify. Process A code With the above pseudo code, is process B able to access sharedResource if mutex is not unlocked? How can I access the sharedResource from process B correctly? Any there any clear visual diagram that explains the relationship between mutexes, threads and processes? Answer What

gdb how to get thread name displayed

There are many threads created in my application. some of the threads name are visible in the gdb while i execute the command ‘info threads’, others are not displayed. How to get all the thread name itself instead of the hex value like 0xb7fe1424 Answer If you upgrade to gdb 7.3 or later, “info thread” will show thread names; at

What is the difference between NPTL and POSIX threads?

What is the basic difference between NPTL and POSIX threads? How have these two evolved? Answer POSIX threads (pthread) is not an implementation, it is a API specification (a standard, on paper, in english) of several functions whose name starts with pthread_ and which are defined in <pthread.h> header. POSIX is also a set of specifications. NPTL is now inside

Why makecontext does not work with pthreads

From makecontext() manual… Due to limitations in the current pthread implementation, makecontext should not be used in programs which link against the pthread(3) library (whether threads are used or not). Now my question is, why it doesn’t work and what are the alternative methods. Actually I’m interested in switching stacks in a user-level thread at some points, but I’m seeing

Is there an invalid pthread_t id?

I would like to call pthread_join for a given thread id, but only if that thread has been started. The safe solution might be to add a variable to track which thread where started or not. However, I wonder if checking pthread_t variables is possible, something like the following code. Where some_invalid_value could be 0, or an implementation dependant ‘PTHREAD_INVALID_ID’

Is it possible to set pthread CPU affinity in OS X?

In Linux there is a sched_setaffinity() function defined in sched.h, but I can’t seem to find anything like that in Mac OS X 10.6 pthreads implementation… If it is not possible to set affinity, what is the default policy in OS X? Answer Mac OS X has Thread Affinity API and you can use it with pthread ID as thread_policy_set(pthread_mach_thread_np(pthreadId),

Advertisement