LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 12-19-2005, 05:33 PM   #1
allomeen
Member
 
Registered: Dec 2005
Posts: 83

Rep: Reputation: 15
stopping usleep function


Hello everyone,
How can i stop the usleep function from sleeping but continue the program after that? What signal should I send?
for example:
while(1)
{
//code
...
usleep(X millisecons);
//code
...
}

the while loop is running on a thread. How can I stop the usleep() from the main thread or anywhere else and continue my code?

Thanks,
Al
 
Old 12-19-2005, 05:47 PM   #2
FLLinux
Member
 
Registered: Jul 2004
Location: USA
Distribution: Fedora 9, LFS 6.3, Unbuntu 8.04, Slax 6.0.7
Posts: 145

Rep: Reputation: 15
Why is the thread using usleep? If it is waiting on something it might be good to use a semaphore or mutex to block the one thread and then signal it to run again.
 
Old 12-19-2005, 05:58 PM   #3
paulsm4
LQ Guru
 
Registered: Mar 2004
Distribution: SusE 8.2
Posts: 5,863
Blog Entries: 1

Rep: Reputation: Disabled
I totally agree with FLLinux.

ANYTIME you hear the word "sleep", it should generally raise yellow flags that maybe you've got a design flaw. A serious design flaw.

NEVER use a "sleep and check" polling loop, if you can simply block instead.

Polling is Bad; Blocking is Good...

Honest...
 
Old 12-19-2005, 06:20 PM   #4
Hko
Senior Member
 
Registered: Aug 2002
Location: Groningen, The Netherlands
Distribution: Debian
Posts: 2,536

Rep: Reputation: 111Reputation: 111
Quote:
How can i stop the usleep function from sleeping but continue the program after that? What signal should I send?
I mostly agree with the above postings. But there can be valid reasons to sleep (e.g. if it's not for polling).

So to answer the question: any signal that can be catched.

Just register a do-nothing signal-handler for the signal of your choice using sigaction(2). then when your thread has catched the signal, usleep() will return -1 with errno set to EINTR.
 
Old 12-19-2005, 07:23 PM   #5
allomeen
Member
 
Registered: Dec 2005
Posts: 83

Original Poster
Rep: Reputation: 15
Thank you guys. sigaction is what i need...
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Calling another function from a function using GTK geminigal Programming 4 07-11-2005 03:15 PM
what are the Hexadecimal function and ASCII function in Perl Bassam Programming 1 06-03-2004 01:44 AM
A main can be changed by a function local without passing anything to the function? ananthbv Programming 10 05-04-2004 01:31 PM
Is the wait function is the same as the sleep function ? Linh Programming 3 04-28-2004 12:39 PM
Perl exec function in linux (and system-function) nazula Programming 1 04-19-2004 12:21 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 10:14 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration