Question (pthread): How to Signal all threads w/o "broadcast"?


 
Thread Tools Search this Thread
Top Forums Programming Question (pthread): How to Signal all threads w/o "broadcast"?
# 1  
Old 05-02-2011
Lightbulb Question (pthread): How to Signal all threads w/o "broadcast"?

Hello all,

Is there any way that I can signal (wake) all threads that I have created without using pthread_cond_broadcast?

Cheers!
Aaron
# 2  
Old 05-03-2011
You can either:
- wake all the threads waiting on the condvar with pthread_cond_broadcast,
- or wake one of the thread waiting on the condvar with pthread_cond_signal (which one is left to the libpthread/OS).

What are you trying to achieve exactly?

Cheers, Loïc
# 3  
Old 05-03-2011
I am trying to achieve this wake up without using pthread calls, such as broadcast.
Basically am trying to find a solution with - for example - using semaphores.

Cheers,
Aaron
# 4  
Old 05-03-2011
This should roughly do the job:
Code:
// postsem and waitsem should be created with values of 0

// to wake up n threads
sem_post(waitsem);
for(i=0; i<n; n++) sem_wait(postsem);

// to wait until woken
sem_wait(waitsem);
sem_post(waitsem);
sem_post(postsem);

Not the most efficient, since it needs 4n+1 semaphore operations to deal with n threads though... And it has race conditions where threads might not sleep if they try to wait when other threads are in the process of being woken up.

Beyond that I'm not sure there's a portable way to do what you want. This is what pthreads is supposed to be for.
# 5  
Old 05-03-2011
Quote:
Originally Posted by mobility
I am trying to achieve this wake up without using pthread calls, such as broadcast.
Basically am trying to find a solution with - for example - using semaphores.

Cheers,
Aaron
Why not using what is offered by Pthreads? Is it a homework, or something like that?

Loïc
# 6  
Old 05-04-2011
Hello all,

Thank you - apparently there is no efficient way to do this other than pthreads I guess - my question was due to curiosity.

@Loic: Well, I am 30 and I wish I could go back to those "homework" days considering how I live today : )

Cheers,
Aaron
# 7  
Old 05-04-2011
Hi Aaron,

Quote:
@Loic: Well, I am 30 and I wish I could go back to those "homework" days considering how I live today : )
I can understand that Smilie

Loïc
Login or Register to Ask a Question

Previous Thread | Next Thread

8 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Bash script - Print an ascii file using specific font "Latin Modern Mono 12" "regular" "9"

Hello. System : opensuse leap 42.3 I have a bash script that build a text file. I would like the last command doing : print_cmd -o page-left=43 -o page-right=22 -o page-top=28 -o page-bottom=43 -o font=LatinModernMono12:regular:9 some_file.txt where : print_cmd ::= some printing... (1 Reply)
Discussion started by: jcdole
1 Replies

2. Solaris

Solaris 10 "Exiting (caught signal 11)"

I get an error after the initializing screen. I am using a DVD/ROM to boot up the installation on a Dell Inspiron 1520. Segmentation fault - core dumped. I have tried to restart multiple times. Please help (1 Reply)
Discussion started by: Jimasaurus
1 Replies

3. Solaris

Trap signal on Window Manager "X" button clicked?

Well, my first post... thanks in advance! Can applications be notified of the X Window close (with "X" button) so the signal handler can run a cleanup process method? About the app: built with GNU C/C++ on Solaris 10, with WxWidgets. It is launched by a shell script as a background task. The... (2 Replies)
Discussion started by: HandsOGold
2 Replies

4. Shell Programming and Scripting

awk command to replace ";" with "|" and ""|" at diferent places in line of file

Hi, I have line in input file as below: 3G_CENTRAL;INDONESIA_(M)_TELKOMSEL;SPECIAL_WORLD_GRP_7_FA_2_TELKOMSEL My expected output for line in the file must be : "1-Radon1-cMOC_deg"|"LDIndex"|"3G_CENTRAL|INDONESIA_(M)_TELKOMSEL"|LAST|"SPECIAL_WORLD_GRP_7_FA_2_TELKOMSEL" Can someone... (7 Replies)
Discussion started by: shis100
7 Replies

5. Solaris

Solaris 10 install issue - "Caught Signal 11"

Rebuilding a server (T2000) from a flash archive I created on another server. Using a Solaris 10/08 DVD to boot from the was going to point it tot he flash archive and pull it over NFS. I've done this many times with success until now. It initially boots off the DVD, you input the... (5 Replies)
Discussion started by: Probos
5 Replies

6. UNIX for Advanced & Expert Users

A question/problem about oracle "tns listener" and "enterprise manager"

hi, I have a problem about the Oracle related components. I'm not able to find any answer yet, and waiting for your responses... Here is the configuration of my system: * an IBM P550 machine, * an AIX 5.3 running on it and * an oracle database, already installed on it. The problem (or... (1 Reply)
Discussion started by: talipk
1 Replies

7. UNIX and Linux Applications

A question/problem about oracle "tns listener" and "enterprise manager"

hi, I have * an IBM P550 machine, * an AIX 5.3 running on it and * an oracle database, already installed on it. The problem (or question of my own) is: Oracle tns listener, "CT_LISTENER", and the enterprise manager (EM) of the instance, which is uniq instance and called... (0 Replies)
Discussion started by: talipk
0 Replies

8. Linux

Strange error "host: isc_taskmgr_create: no available threads"

Dear Srs, I'm getting this error on a Linux box, running Apache 2.0.52: "host: isc_taskmgr_create: no available threads" Making some search for those strings in Google, didn't tell me anything about this.. appears to be related to SELinux, but it's disabled in the box. Any idea about... (0 Replies)
Discussion started by: Santi
0 Replies
Login or Register to Ask a Question