Go Back   The UNIX and Linux Forums > Operating Systems > Linux
Search Forums:



Linux RedHat, Ubuntu, SUSE, Fedora, Debian, Mandriva, Slackware, Gentoo linux, PCLinuxOS. All Linux questions here!

Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 02-10-2011
Registered User
 

Join Date: Nov 2010
Location: Tel Aviv
Posts: 20
Thanks: 0
Thanked 1 Time in 1 Post
Stuck in pthread_cond_signal()

I am developing a multi-threaded library that helps the transformation of messages between threads in different processes using shared memory.

I am using the pthreads condition facility in order to synchronize access to the shared memory slots through which the messages are passed.

My test program got stuck. Obviously, most of the threads were stuck in the call to pthread_cond_wait(), waiting for a shared memory slot to become vacant.
However, what stuck the program was one of the threads who got stuck in
the call to pthread_cond_signal().
Obviously, since he got stuck there, none of the other threads awoke and consequently, the entire test program got stuck.

I will also mention that I am using the PTHREAD_PROCESS_SHARED attribute for the condition variable.

I am running on Ubuntu Linux 10.04.

Has anybody encountered a situation where pthread_cond_signal() is stuck?
Any idea about the reasons for this situation?

Thanks.
Sponsored Links
    #2  
Old 02-10-2011
fpmurphy's Avatar
who?
 

Join Date: Dec 2003
Location: /dev/ph
Posts: 4,043
Thanks: 35
Thanked 282 Times in 263 Posts
Quote:
Has anybody encountered a situation where pthread_cond_signal() is stuck?
Sure. It is a common occurrence. Usually due to invalid assumptions regarding pthreads.

However if you want us to help you, you need to show us your code or, preferably, a short working example which demonstrates the problem.
Sponsored Links
    #3  
Old 02-13-2011
Registered User
 

Join Date: Nov 2010
Location: Tel Aviv
Posts: 20
Thanks: 0
Thanked 1 Time in 1 Post
Thank you for responding.
Producing the code for the forum would not be possible, if only because it is a part of a complicated project. I don't currently have a short working example.

My "waiter" code looks like:


Code:
pthread_mutex_lock(pWaiter->getMutex());
while (!pWaiter->getFlag())
pthread_cond_wait(pWaiter->getCond(), pWaiter->getMutex());
pthread_mutex_unlock(pWaiter->getMutex());

The "waker" side looks like:


Code:
pthread_mutex_lock(pWaitForRequest->getMutex());
pWaitForRequest->setFlag(true);
pthread_cond_signal(pWaitForRequest->getCond());
pthread_mutex_unlock(pWaitForRequest->getMutex());

Could someone who has experienced such a problem can suggest typical reeasons why the pthread_cond_signal() gets stuck in such a usage.

Thanks.
Sponsored Links
Closed Thread

Tags
condition, linux, pthreads

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Problem with using pthread_cond_wait and pthread_cond_signal sourabhforu UNIX for Advanced & Expert Users 5 11-03-2010 03:23 PM
help! im stuck.. cherrywinter Shell Programming and Scripting 1 08-01-2008 01:55 PM
Got stuck so plz help boris Shell Programming and Scripting 3 04-11-2007 01:03 AM
stuck....! moxxx68 UNIX for Advanced & Expert Users 0 12-10-2004 10:52 PM
I'm stuck Fender UNIX for Dummies Questions & Answers 3 01-07-2001 01:14 PM



All times are GMT -4. The time now is 11:43 PM.