pthreads

Conditional wait overhead

When using boost::conditional_variable, ACE_Conditional or directly pthread_cond_wait, is there any overhead for the waiting itself? These are more specific issues that trouble be: After the waiting thread is unscheduled, will it be scheduled back before the wait expires and then unscheduled again or it will stay unscheduled until sign...

pthread_cond_broadcast problem

Using pthreads in linux 2.6.30 I am trying to send a single signal which will cause multiple threads to begin execution. The broadcast seems to only be received by one thread. I have tried both pthread_cond_signal and pthread cond_broadcast and both seem to have the same behavior. For the mutex in pthread_cond_wait, I have tried both ...

Semaphore Syncing

I have two semaphores x (initially at 1) , and y (initially at 0). My thread function code is somewhat like this: ... wait(x); //setting some vars signal(x); wait(y); ... I want to ensure that the threads wait on y in line, ie. if the first thread completed the x-guarded section first, it should get to wait on y first, & so on....

Wait & Signal order

If the following pieces of code execute in the order in which I have put them, can I be sure that thread 1 is awoken first by thread 3, later followed by thread 2? main: sem_init(&x,0,0); thread 1: sem_wait(&x); thread 2: sem_wait(&x); thread 3: sem_post(&x); ...

GDB Quirks with Thread Process

I am debugging a process with multiple threads in GDB. I compiled the sole source file with the -g flag. However, while running in GDB, the following scenario occurs: Program received signal SIGSEGV, Segmentation fault. [Switching to Thread 0xb7fe2b70 (LWP 2604)] 0x00000011 in ?? () Prior to the switch, the particular thread executes...

Possible Stack Corruption

With reference to my previous question about GDB not pinpointing the SIGSEGV point, My thread code is as follows: void *runner(void *unused) { do { sem_wait(&x); ... if(/*condition 1 check*/) { sem_post(&x); sleep(5); sem_wait(&x); if(/*repeat condition 1 check; after atleast 5 seconds*/) { printf("LEAVING....

Clean up pthread resources when programme terminate

I have create a thread using pthread. My worker routine is a infinite loop. What is the design pattern to terminate and clean up all the resources of the pthread when my main programme exit? pthread_create(&thread, NULL, worker, NULL); void* worker(void* arg){ while(true){ //do something } } Thanks ...

Strange SEGFAULTS using fprintf

I'm having a very tough time debugging a multi-threaded C application that I've made a few changes to. I've been unable to use GDB to help identify the issue(see below code for more info). The following code is from one of the tasks that is opened in its own thread. I've snipped out most of the code following the problem. void tskPr...

PThread RWLock Deadlocking with Recursive Locks

I've been working on a small sand-boxed example to help me figure out how to use rwlocks. Everything seems fairly straightforward, however I'm getting deadlocks in my example every once and a while and don't understand why it's happening. I've put the code example on pastebin because it's more than a few lines of code: http://pastebin.o...

how to manage EINTR errno in sem_timedwait

Can you help me to understand why it is recommended to use: while ((s = sem_timedwait(&sem, &ts)) == -1 && errno == EINTR) continue; // Restart when interrupted by handler (EINTR: The call was interrupted by a signal handler) Instead of simply: s = sem_timedwait(&sem, &ts); In witch cases I have to manage EINTR ? ...

Signal Dispositions in Pthreads

The man page for pthreads mentions: POSIX.1 also requires that threads share a range of other attributes (i.e., these attributes are process-wide rather than per-thread): ... - signal dispositions ... What do "signal dispositions" mean? ...

Using pthread_create stops my method from working. Why? Using C.

I have a method which is is meant to write information into a struct. I want to make it run as a thread. If I call it by itself, as childWriter((void*) &sa) it works. If I call pthread_create(&writerChild, NULL, childWriter, (void*) &sa), it no longer works. It doesn't write to the shared object. This is driving me mad. Why isn't it w...

Exiting gracefully from a multithreaded process

I'm running a multi-threaded C program (process?) , making use of semaphores & pthreads. The threads keep interacting, blocking, waking & printing prompts on stdout continuously, without any human intervention. I want to be able to exit this process (gracefully after printing a message & putting down all threads, not via a crude CTRL+C S...

Cancelling a Blocked Pthread

How do I cause a thread to respond to pthread_cancel() if it is blocked on a sem_wait()? ...

Pthread RWLock on MAC Deadlocking but not on Linux?

I've been experimenting with rwlock's on Mac and am experiencing something that seems to me shouldn't be happening. There's some weird combination of using read/write locks with recursive read locks that is deadlocking, but shouldn't be. I posted the code on pastebin because it's more than just a snippet. The way this code is written s...

how are pthreads on linux seen by scheduler

I've a question regarding pthread implementation on Linux. Suppose a process has 5 threads. Now how does the scheduler sees these threads (or doesnt see at all). e.g. When scheduler is invoked, does it only schedule the main process, and then its the onus of the main process to schedule between each of its thread. Or is it the other wa...

QT: How to open several windows (QWidgets) at once?

Hello! I'm doing web interface testing program which should open two urls in two webkit windows simultaneously. I already did the code for the test automation. 1) User pushes 'Go' button and webkit (QWidget) window opens 2) TestBot class object performs tests 3) Closes Now my question: After clicking on the button 'Go', how do I op...

Sleeping in a Thread (C / POSIX Threads)

I am developing a multithreaded application that makes use of POSIX Threads. I am using threads for doing a periodical job and for that purpose I am using usleep(3) to suspend thread execution. My question is how can I cancel usleep() timer from the main thread, I tried pthread_kill(thread, SIGALRM) but it has a global effect which resul...

How pthreads does cross-threading and scheduling

Hi everyone I was wondering, how does pthreads-win32 (windows implementation of pthreads) implement cross-threading? Is it written exclusively with windows API? I checked some of the sources and it seems that most is indeed written with windows API, tho i was wondering if it uses windows scheduler to switch between threads (and cores) a...

Suggestions to Optimize Blocking Queue implementation

T BlockingQueue<T>::pop( ) { pthread_mutex_lock(&lock); if (list.empty( )) { pthread_cond_wait(&cond) ; } T temp = list.front( ); list.pop_front( ); pthread_mutex_unlock(&lock); return temp; } The above is the pop operation as defined for a templatized concurrent blocking qu...