Sponsored Content
Operating Systems Linux Stuck in pthread_cond_signal() Post 302496256 by dhzdh on Sunday 13th of February 2011 05:11:41 AM
Old 02-13-2011
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.
 

10 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

stuck....!

I have been busy reading away on devices and filesystems and I am stuck on a particular subject matter.. I'm not understanding the concept behind mknod mkfifo makedev or related commands.. can anyone shed some light on the subject.! any feedback welcome! moxxx68 (0 Replies)
Discussion started by: moxxx68
0 Replies

2. UNIX for Dummies Questions & Answers

stuck and confused

#!/bin/bash echo $1 | cat - $2 >> /tmp/$$ && mv /tmp/$$ $2 im trying to get the first argument to go in the middle of the second argument which is a file, anyone any ideas. i have only managed to get it to go on the end or the front. been fiddling about with wc -l, i get the number of lines... (5 Replies)
Discussion started by: iago
5 Replies

3. Programming

I'm stuck :(

Suppose that I have some data: 12,30 12,45 2,3 7,8 3,9 30, 8 45,54 56,65 Where (a,b) indicates that a is connected to b. I want to get all connected nodes to one point. For instance, the output of the above example should be something like: Group 1 2,3 3,9 Group 2 12,30 12,45... (4 Replies)
Discussion started by: Legend986
4 Replies

4. UNIX for Dummies Questions & Answers

stuck with a script

Hi There I am pretty new to UNIX and have only been using it from a basic point of view,I now want to start using it and learning more , have got a whole lot of books and documentation from the web and am slowly learning.I have written a get script in windows :- lcd E:\MAIN\PRO\FILES\MAINDB... (1 Reply)
Discussion started by: FOCKER
1 Replies

5. Shell Programming and Scripting

help! im stuck..

I want to search for the line with the group name and add the user into the group. The file format is the same as /etc/group The code i wrote is egrep "^$newGID" $group >/dev/null FS=":" oldData=awk -F: '{print $3}' newData= "$oldData,$newUser" sed -n $4/$newData $group but a friend... (1 Reply)
Discussion started by: cherrywinter
1 Replies

6. Shell Programming and Scripting

I am stuck in my script

Hi All I have script that find 777 dir with specific extension like .php .Now after finding all 777 directory i will place in httpd.conf using a directory directive ,Now i was not do that,if directory entry exitst in httpd.conf then script ignor it dont show me at stdout else if it dont find... (2 Replies)
Discussion started by: aliahsan81
2 Replies

7. Homework & Coursework Questions

stuck on assignment

I was given this to do, Write a Shell script to automatically check that a specified user is logged in to the computer. The program should allow the person running the script to specify the name of the user to be checked, the frequency in seconds at which the script should check. If a... (1 Reply)
Discussion started by: operator
1 Replies

8. UNIX for Dummies Questions & Answers

Undefined reference to `pthread_cond_signal@GLIBC_2.3.2

When i try to make my c project i am getting an error message like this : ../../../lib/linux/libxml.so: undefined reference to `pthread_cond_signal@GLIBC_2.3.2' Please help me in resolving this. (0 Replies)
Discussion started by: dhivyam
0 Replies

9. AIX

mget is stuck

Hi, below are the commands I use to get many gif files from /usr/local/images directory, the command just getting stuck at mget, nothing is moving cd /usr/local/images binary mget *.gif:wall: close quit (3 Replies)
Discussion started by: dateez
3 Replies

10. Debian

Stuck in BIOS

okay,i made a grave mistake in installing the base bare bones install of debian. here i have edited this from the original. this morning when i got home from work i did some searching and then just shut the system down via the mechanical off on switch. waited a few minutes and then restarted... (0 Replies)
Discussion started by: cowLips
0 Replies
PTHREAD_COND_BROADCAST(P)				     POSIX Programmer's Manual					 PTHREAD_COND_BROADCAST(P)

NAME
pthread_cond_broadcast, pthread_cond_signal - broadcast or signal a condition SYNOPSIS
#include <pthread.h> int pthread_cond_broadcast(pthread_cond_t *cond); int pthread_cond_signal(pthread_cond_t *cond); DESCRIPTION
These functions shall unblock threads blocked on a condition variable. The pthread_cond_broadcast() function shall unblock all threads currently blocked on the specified condition variable cond. The pthread_cond_signal() function shall unblock at least one of the threads that are blocked on the specified condition variable cond (if any threads are blocked on cond). If more than one thread is blocked on a condition variable, the scheduling policy shall determine the order in which threads are unblocked. When each thread unblocked as a result of a pthread_cond_broadcast() or pthread_cond_signal() returns from its call to pthread_cond_wait() or pthread_cond_timedwait(), the thread shall own the mutex with which it called pthread_cond_wait() or pthread_cond_timedwait(). The thread(s) that are unblocked shall contend for the mutex according to the scheduling policy (if applicable), and as if each had called pthread_mutex_lock(). The pthread_cond_broadcast() or pthread_cond_signal() functions may be called by a thread whether or not it currently owns the mutex that threads calling pthread_cond_wait() or pthread_cond_timedwait() have associated with the condition variable during their waits; however, if predictable scheduling behavior is required, then that mutex shall be locked by the thread calling pthread_cond_broadcast() or pthread_cond_signal(). The pthread_cond_broadcast() and pthread_cond_signal() functions shall have no effect if there are no threads currently blocked on cond. RETURN VALUE
If successful, the pthread_cond_broadcast() and pthread_cond_signal() functions shall return zero; otherwise, an error number shall be returned to indicate the error. ERRORS
The pthread_cond_broadcast() and pthread_cond_signal() function may fail if: EINVAL The value cond does not refer to an initialized condition variable. These functions shall not return an error code of [EINTR]. The following sections are informative. EXAMPLES
None. APPLICATION USAGE
The pthread_cond_broadcast() function is used whenever the shared-variable state has been changed in a way that more than one thread can proceed with its task. Consider a single producer/multiple consumer problem, where the producer can insert multiple items on a list that is accessed one item at a time by the consumers. By calling the pthread_cond_broadcast() function, the producer would notify all consumers that might be waiting, and thereby the application would receive more throughput on a multi-processor. In addition, pthread_cond_broad- cast() makes it easier to implement a read-write lock. The pthread_cond_broadcast() function is needed in order to wake up all waiting readers when a writer releases its lock. Finally, the two-phase commit algorithm can use this broadcast function to notify all clients of an impending transaction commit. It is not safe to use the pthread_cond_signal() function in a signal handler that is invoked asynchronously. Even if it were safe, there would still be a race between the test of the Boolean pthread_cond_wait() that could not be efficiently eliminated. Mutexes and condition variables are thus not suitable for releasing a waiting thread by signaling from code running in a signal handler. RATIONALE
Multiple Awakenings by Condition Signal On a multi-processor, it may be impossible for an implementation of pthread_cond_signal() to avoid the unblocking of more than one thread blocked on a condition variable. For example, consider the following partial implementation of pthread_cond_wait() and pthread_cond_sig- nal(), executed by two threads in the order given. One thread is trying to wait on the condition variable, another is concurrently execut- ing pthread_cond_signal(), while a third thread is already waiting. pthread_cond_wait(mutex, cond): value = cond->value; /* 1 */ pthread_mutex_unlock(mutex); /* 2 */ pthread_mutex_lock(cond->mutex); /* 10 */ if (value == cond->value) { /* 11 */ me->next_cond = cond->waiter; cond->waiter = me; pthread_mutex_unlock(cond->mutex); unable_to_run(me); } else pthread_mutex_unlock(cond->mutex); /* 12 */ pthread_mutex_lock(mutex); /* 13 */ pthread_cond_signal(cond): pthread_mutex_lock(cond->mutex); /* 3 */ cond->value++; /* 4 */ if (cond->waiter) { /* 5 */ sleeper = cond->waiter; /* 6 */ cond->waiter = sleeper->next_cond; /* 7 */ able_to_run(sleeper); /* 8 */ } pthread_mutex_unlock(cond->mutex); /* 9 */ The effect is that more than one thread can return from its call to pthread_cond_wait() or pthread_cond_timedwait() as a result of one call to pthread_cond_signal(). This effect is called "spurious wakeup". Note that the situation is self-correcting in that the number of threads that are so awakened is finite; for example, the next thread to call pthread_cond_wait() after the sequence of events above blocks. While this problem could be resolved, the loss of efficiency for a fringe condition that occurs only rarely is unacceptable, especially given that one has to check the predicate associated with a condition variable anyway. Correcting this problem would unnecessarily reduce the degree of concurrency in this basic building block for all higher-level synchronization operations. An added benefit of allowing spurious wakeups is that applications are forced to code a predicate-testing-loop around the condition wait. This also makes the application tolerate superfluous condition broadcasts or signals on the same condition variable that may be coded in some other part of the application. The resulting applications are thus more robust. Therefore, IEEE Std 1003.1-2001 explicitly documents that spurious wakeups may occur. FUTURE DIRECTIONS
None. SEE ALSO
pthread_cond_destroy() , pthread_cond_timedwait() , the Base Definitions volume of IEEE Std 1003.1-2001, <pthread.h> COPYRIGHT
Portions of this text are reprinted and reproduced in electronic form from IEEE Std 1003.1, 2003 Edition, Standard for Information Technol- ogy -- Portable Operating System Interface (POSIX), The Open Group Base Specifications Issue 6, Copyright (C) 2001-2003 by the Institute of Electrical and Electronics Engineers, Inc and The Open Group. In the event of any discrepancy between this version and the original IEEE and The Open Group Standard, the original IEEE and The Open Group Standard is the referee document. The original Standard can be obtained online at http://www.opengroup.org/unix/online.html . IEEE
/The Open Group 2003 PTHREAD_COND_BROADCAST(P)
All times are GMT -4. The time now is 09:13 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy