linux Sleep command

Programming Topics (Computer Chess) and technical aspects as test techniques, book building, program tuning etc

Moderator: Andres Valverde

linux Sleep command

Postby Daniel Shawul » 18 Oct 2005, 06:37

Hi
Is there an equivalent function for the
windows Sleep command in linux?
i use Sleep(0) to give up time slice for threads.
Also what is the equivalent test and set operation for linux?(IE InterlockedExchange in windows).
if there is a free portable library, i would like to use it.
someone suggested PostgreSql, but i can't locate where the files are.
thanks in advance
daniel
User avatar
Daniel Shawul
 
Posts: 366
Joined: 28 Sep 2004, 09:33
Location: Ethiopia

Re: linux Sleep command

Postby Alessandro Scotti » 18 Oct 2005, 12:16

Hi Daniel,
you can try usleep on Linux. I use usleep(1000) as equivalent to Sleep(1).
User avatar
Alessandro Scotti
 
Posts: 306
Joined: 20 Nov 2004, 00:10
Location: Rome, Italy

Re: linux Sleep command

Postby Sven Schüle » 18 Oct 2005, 12:30

Alessandro Scotti wrote:Hi Daniel,
you can try usleep on Linux. I use usleep(1000) as equivalent to Sleep(1).

Hi Alessandro,

does Sleep(N) sleep N seconds or N milliseconds on Windows? If "N seconds" is correct then you should use usleep(1000000) on Linux because usleep(U) sleeps U microseconds.

Sven
User avatar
Sven Schüle
 
Posts: 240
Joined: 26 Sep 2004, 20:19
Location: Berlin, Germany

Re: linux Sleep command

Postby Alessandro Scotti » 18 Oct 2005, 13:02

Sven Sch?le wrote:does Sleep(N) sleep N seconds or N milliseconds on Windows? If "N seconds" is correct then you should use usleep(1000000) on Linux because usleep(U) sleeps U microseconds.


Hi Sven,
Sleep() uses milliseconds on Windows. In my case I use Sleep(1) to yield the rest of the time slice, however this may not apply directly to Daniel because he's using Sleep(0) and that behaves differently in Windows. When I ported the engine to Unix I used usleep(1000) as a simple translation of Sleep(1) but did not investigate further if and how smaller intervals would work. For the use I do, wasting one millisecond is not much important! :-) Daniel may need to look better into this though.
User avatar
Alessandro Scotti
 
Posts: 306
Joined: 20 Nov 2004, 00:10
Location: Rome, Italy

Re: linux Sleep command

Postby Daniel Shawul » 18 Oct 2005, 14:46

Hi alessandro
you are right, i can't use Sleep(1). It is done inside search and
I assumed there will probably be an equivalent sleep command when
i started.
I managed to find some linux kernel spinlocks on the net,
but unfortunatley this has to be done for each platform.
I guess i will leave it up to linux users to add their own locks :(
thanks anyways
daniel
User avatar
Daniel Shawul
 
Posts: 366
Joined: 28 Sep 2004, 09:33
Location: Ethiopia

Re: linux Sleep command

Postby Dann Corbit » 18 Oct 2005, 17:56

Daniel Shawul wrote:Hi alessandro
you are right, i can't use Sleep(1). It is done inside search and
I assumed there will probably be an equivalent sleep command when
i started.
I managed to find some linux kernel spinlocks on the net,
but unfortunatley this has to be done for each platform.
I guess i will leave it up to linux users to add their own locks :(
thanks anyways
daniel


You might look at the Berkeley licensed PostgreSQL kernel.
They have spinlocks in there for just about every platform.
Dann Corbit
 


Return to Programming and Technical Discussions

Who is online

Users browsing this forum: No registered users and 7 guests

cron