From mboxrd@z Thu Jan 1 00:00:00 1970 X-Google-Thread: fa528,f4a4c1fd65fe8154,start X-Google-Attributes: gidfa528,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news1.google.com!proxad.net!fr.ip.ndsoftware.net!news.newsland.it!aioe.org!not-for-mail From: Andy Fong Newsgroups: comp.unix.tru64 Subject: Sleep and interrupt problem? Date: Thu, 24 Mar 2005 16:08:47 -0500 Organization: Aioe.org NNTP Server Message-ID: NNTP-Posting-Host: pRSZwVU9bN+XWPEtXAtsJA.domitilla.aioe.org Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 8bit X-Complaints-To: abuse@aioe.org NNTP-Posting-Date: Thu, 24 Mar 2005 21:09:26 +0000 (UTC) User-Agent: Pan/0.14.2 (This is not a psychotic episode. It's a cleansing moment of clarity.) Xref: g2news1.google.com comp.unix.tru64:628 I am writing a device driver. In some situation, I need to go to sleep and wait for an interrupt to wake me up so I don't use up the cpu cycles. Here is what I do: If (operation not done yet) { EnableInterrupt; if (operation not done yet) { tsleep for 1 second; } } I run into problem where the sleep times out very often which should never happen. I suspect that tsleep/sleep is not atomic interrupt comes in after the sleep function call and before it actually goes to sleep. I tried to take out the 2nd check and go to sleep immediately after enabling the interrupt but it doesn't help at all. I can work around the problem by sleeping for 10 msec at a time in a loop and break out the loop if the operation is done but that not very efficient. Is there any way to do atomic sleep? Thank you for any help. Andy