Page 1 of 1

linux Sleep command

PostPosted: 18 Oct 2005, 06:37
by Daniel Shawul
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

Re: linux Sleep command

PostPosted: 18 Oct 2005, 12:16
by Alessandro Scotti
Hi Daniel,
you can try usleep on Linux. I use usleep(1000) as equivalent to Sleep(1).

Re: linux Sleep command

PostPosted: 18 Oct 2005, 12:30
by Sven Schüle
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

Re: linux Sleep command

PostPosted: 18 Oct 2005, 13:02
by Alessandro Scotti
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.

Re: linux Sleep command

PostPosted: 18 Oct 2005, 14:46
by Daniel Shawul
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

Re: linux Sleep command

PostPosted: 18 Oct 2005, 17:56
by Dann Corbit
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.