12-16-2011
You can sleep "indefinitely" with the pause() function, defined in <unistd.h>, which will sleep until you receive a signal.
You can wake a pause()d thread with pthread_kill() to send some signal that won't kill it (SIGCONT seems appropriate).
Though if you're expecting threads to cooperate, you should look into conditions and mutexes.
7 More Discussions You Might Find Interesting
1. UNIX for Advanced & Expert Users
Im old to Unix but new to scripting
I have a MacBook running osx that I want to use as an nfs client. The server will be a linux box with a wake on lan card. Here's the idea. Run a cron command on the mac every minute that checks if I am on my home wireless network (the linux box is wired to... (0 Replies)
Discussion started by: anon0mus
0 Replies
2. Shell Programming and Scripting
m old to Unix but new to scripting
I have a MacBook running osx that I want to use as an nfs client. The server will be a linux box with a wake on lan card. Here's the idea. Run a cron command on the mac every minute that checks if I am on my home wireless network (the linux box is wired to... (6 Replies)
Discussion started by: anon0mus
6 Replies
3. Programming
I have two threads: one maintains a thread-safe message queue (handle this queue at the beginning of every loop) and deals with tcp connections, the other one posts message to the former one. the problem is, while the former one was blocking at epoll_wait, it's not sure that how long until the... (0 Replies)
Discussion started by: cometeor
0 Replies
4. UNIX for Advanced & Expert Users
Hello, I'm searching for a proper way to let the kernel space ISR(implemented in a kernel module) wake up a user space thread on a hardware interrupt.
Except for sending a real-time signal, is it possible to use a semaphore?
I've searched it on google, but it seems impossible to share a... (0 Replies)
Discussion started by: aaronwong
0 Replies
5. Shell Programming and Scripting
This is a very crude attempt in Bash at something that I needed but didn't seem to find in the 'sleep' command. However, I would like to be able to do it without the need for the temp file. Please go easy on me if this is already possible in some other way:
How many times have you used the... (5 Replies)
Discussion started by: deckard
5 Replies
6. UNIX for Dummies Questions & Answers
Hi all,
Is it possible to do the following in Linux (kernel 2.6.x):
- A user-space thread goes to "sleep". Using any call/mechanism
- On a hardware generated interrupt, the Interrupt handler (ISR) "wakes" the sleeping user-thread.
I have seen wait_event() and wake_up() but it appears... (1 Reply)
Discussion started by: agaurav
1 Replies
7. UNIX for Dummies Questions & Answers
I'm a OS X user (MacBook Pro, OS X Lion) and I need it to wake up on Mondays, Wednesdays, Thursdays and Saturdays at 9:00 AM
on the rest of the days of the week at 7:00
I issue the following commands:
sudo pmset repeat wake MWRS 09:00:00 for the former
sudo pmset repeat wake TFU... (1 Reply)
Discussion started by: scrutinizerix
1 Replies
LEARN ABOUT LINUX
pthread_kill
PTHREAD_KILL(3) Linux Programmer's Manual PTHREAD_KILL(3)
NAME
pthread_kill - send a signal to a thread
SYNOPSIS
#include <signal.h>
int pthread_kill(pthread_t thread, int sig);
Compile and link with -pthread.
DESCRIPTION
The pthread_kill() function sends the signal sig to thread, another thread in the same process as the caller. The signal is asynchronously
directed to thread.
If sig is 0, then no signal is sent, but error checking is still performed; this can be used to check for the existence of a thread ID.
RETURN VALUE
On success, pthread_kill() returns 0; on error, it returns an error number, and no signal is sent.
ERRORS
ESRCH No thread with the ID thread could be found.
EINVAL An invalid signal was specified.
CONFORMING TO
POSIX.1-2001.
NOTES
Signal dispositions are process-wide: if a signal handler is installed, the handler will be invoked in the thread thread, but if the dispo-
sition of the signal is "stop", "continue", or "terminate", this action will affect the whole process.
SEE ALSO
kill(2) sigaction(2), sigpending(2), pthread_self(3), pthread_sigmask(3), raise(3), pthreads(7), signal(7)
COLOPHON
This page is part of release 3.27 of the Linux man-pages project. A description of the project, and information about reporting bugs, can
be found at http://www.kernel.org/doc/man-pages/.
Linux 2009-01-28 PTHREAD_KILL(3)