Sponsored Content
Top Forums Programming How to wait on multiple semaphores/mutexes Post 302083393 by siegfried on Saturday 5th of August 2006 01:28:18 PM
Old 08-05-2006
How to wait on multiple semaphores/mutexes

I thought one used the select function to wait on multiple semaphores but according to http://opengroup.org/onlinepubs/0079...sh/select.html, the select function is only good for I/O features (like pipes and fifos).

How can I block for multiple semaphores? What if I have a mixture of things to wait on like semaphores from sem.h, semaphores from semaphore.h and mutexes? Am I out of luck?


Thanks,
Siegfried
 

10 More Discussions You Might Find Interesting

1. Programming

C++ variable scope and mutexes

I've been wondering if I can make mutexes much easier to use in C++ with creative use of a locking class and variable scope, but I'm not sure if things happen in the order I want. Here's pseudocode for something that could use the class: int someclass::getvalue() { int retval; ... (0 Replies)
Discussion started by: Corona688
0 Replies

2. Programming

Howto spawn multiple child processes and wait?

As far as I can tell, the bash wait command waits for a logical "AND" of all the child processes. Assuming I am coding in C: (1) What is the function I would use to create multiple bash child process running perl? (2) What is the function I would use to reinvent the bash wait command so I... (4 Replies)
Discussion started by: siegfried
4 Replies

3. Shell Programming and Scripting

Need to execute 2 scripts, wait, execute 2 more wait, till end of file

:cool: I need to execute a shell script to do the following: cat a file run two back ground processes using the first two values from the file wait till those background processes finish run two more background processes using the next two values from the file wait till those background... (1 Reply)
Discussion started by: halo98
1 Replies

4. Shell Programming and Scripting

semaphores

Hi Friends, If i execute this command it comes back with 300 lines: ipcs|grep cerebrus >>> i would like to clear the semaphores but ipcrm can remove one id at a time. is there a quicker way of removing semaphores maybe using awk? Regards, (1 Reply)
Discussion started by: kekanap
1 Replies

5. Programming

semaphores using up and down

been searching around on how to use an up and down function with semaphores but i can't find an example. i looked into using: "semop" but i have no idea how to use it. I have been able to declared the semaphores using semget and initializing them using semctl. (7 Replies)
Discussion started by: ddx08
7 Replies

6. Shell Programming and Scripting

wait command - cat it wait for not-chile process?

Did not use 'wait' yet. How I understand by now the wait works only for child processes, started background. Is there any other way to watch completion of any, not related process (at least, a process, owned by the same user?) I need to start a background process, witch will be waiting... (2 Replies)
Discussion started by: alex_5161
2 Replies

7. UNIX for Dummies Questions & Answers

pthread condition variables and mutexes?

I am trying to understand the exact difference between condition variables and mutexes in thread synchronization ?. I know mutex will control the thread access to shared data and condition variables will be useful for waiting for certain event or condition to occur . But I couldn't understand why... (2 Replies)
Discussion started by: siddaonline
2 Replies

8. Programming

locking mutexes, threads & semahores

What is the difference between mutex_lock and pthread_mutex_lock ? Should I use both when using binary semaphores. Also, what is the difference between using a binary semaphore and a counting semaphore where you wait on the condition variable ? (1 Reply)
Discussion started by: joey
1 Replies

9. Shell Programming and Scripting

Script needed to wait for existence of multiple files

Hi Forum. I need a script to wait for all multiple trigger files to be present or else go to sleep for 10 seconds (Number of trigger files can vary). I tried to search on the forum but was not able to find a solution. I found this code on this forum but it's not working as expected: for... (6 Replies)
Discussion started by: pchang
6 Replies

10. Shell Programming and Scripting

calling a shell script in background and wait using "wait" in while loop

Hi, I am facing a strange issue, when i call a script from my while loop in background it doesnt go in background, despite the wait i put below the whil loop it goes forward even before the process put in background is completed. cat abc.txt | while read -u4 line do #if line contains #... (2 Replies)
Discussion started by: mihirvora16
2 Replies
SIGWAIT(3P)						     POSIX Programmer's Manual						       SIGWAIT(3P)

PROLOG
This manual page is part of the POSIX Programmer's Manual. The Linux implementation of this interface may differ (consult the correspond- ing Linux manual page for details of Linux behavior), or the interface may not be implemented on Linux. NAME
sigwait - wait for queued signals SYNOPSIS
#include <signal.h> int sigwait(const sigset_t *restrict set, int *restrict sig); DESCRIPTION
The sigwait() function shall select a pending signal from set, atomically clear it from the system's set of pending signals, and return that signal number in the location referenced by sig. If prior to the call to sigwait() there are multiple pending instances of a single signal number, it is implementation-defined whether upon successful return there are any remaining pending signals for that signal number. If the implementation supports queued signals and there are multiple signals queued for the signal number selected, the first such queued signal shall cause a return from sigwait() and the remainder shall remain queued. If no signal in set is pending at the time of the call, the thread shall be suspended until one or more becomes pending. The signals defined by set shall have been blocked at the time of the call to sigwait(); otherwise, the behavior is undefined. The effect of sigwait() on the signal actions for the signals in set is unspecified. If more than one thread is using sigwait() to wait for the same signal, no more than one of these threads shall return from sigwait() with the signal number. Which thread returns from sigwait() if more than a single thread is waiting is unspecified. Should any of the multiple pending signals in the range SIGRTMIN to SIGRTMAX be selected, it shall be the lowest numbered one. The selec- tion order between realtime and non-realtime signals, or between multiple pending non-realtime signals, is unspecified. RETURN VALUE
Upon successful completion, sigwait() shall store the signal number of the received signal at the location referenced by sig and return zero. Otherwise, an error number shall be returned to indicate the error. ERRORS
The sigwait() function may fail if: EINVAL The set argument contains an invalid or unsupported signal number. The following sections are informative. EXAMPLES
None. APPLICATION USAGE
None. RATIONALE
To provide a convenient way for a thread to wait for a signal, this volume of IEEE Std 1003.1-2001 provides the sigwait() function. For most cases where a thread has to wait for a signal, the sigwait() function should be quite convenient, efficient, and adequate. However, requests were made for a lower-level primitive than sigwait() and for semaphores that could be used by threads. After some con- sideration, threads were allowed to use semaphores and sem_post() was defined to be async-signal and async-cancel-safe. In summary, when it is necessary for code run in response to an asynchronous signal to notify a thread, sigwait() should be used to handle the signal. Alternatively, if the implementation provides semaphores, they also can be used, either following sigwait() or from within a signal handling routine previously registered with sigaction(). FUTURE DIRECTIONS
None. SEE ALSO
Signal Concepts, Realtime Signals, pause(), pthread_sigmask(), sigaction(), sigpending(), sigsuspend(), sigwaitinfo(), the Base Definitions volume of IEEE Std 1003.1-2001, <signal.h>, <time.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 SIGWAIT(3P)
All times are GMT -4. The time now is 11:55 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy