Sponsored Content
Top Forums Programming How to sleep and wake a thread??? Post 302582537 by JohnGraham on Friday 16th of December 2011 09:41:31 AM
Old 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

Wake on Lan script

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

Wake on LAN script

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

how to wake up a thread that blocking at epoll_wait?

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

wake up user space thread from kernel space ISR

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

Wrapping 'sleep' with my 'resleep' function (Resettable sleep)

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

Linux Device Driver: how can an ISR wake up a user-thread?

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

Computer wake commands

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
PTHREAD_KILL(2) 					      BSD System Calls Manual						   PTHREAD_KILL(2)

NAME
pthread_kill -- send a signal to a specified thread SYNOPSIS
#include <signal.h> int pthread_kill(pthread_t thread, int sig); DESCRIPTION
The pthread_kill() function sends a signal, specified by sig, to a thread, specified by thread. If sig is 0, error checking is performed, but no signal is actually sent. RETURN VALUES
If successful, pthread_kill() returns 0. Otherwise, an error number is returned. ERRORS
The pthread_kill() function will fail if: [ESRCH] thread is an invalid thread ID. [EINVAL] sig is an invalid or unsupported signal number. [ENOTSUP] thread was not created by pthread_create() and does not support being killed with pthread_kill() LEGACY SYNOPSIS
#include <pthread.h> #include <signal.h> The include file <pthread.h> is necessary. SEE ALSO
kill(2), pthread_self(3), raise(3), compat(5) STANDARDS
pthread_kill() conforms to ISO/IEC 9945-1:1996 (``POSIX.1'') BSD
Feb 05, 2002 BSD
All times are GMT -4. The time now is 06:37 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy