Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
![]() |
![]() |
Home -> Community -> Usenet -> c.d.o.server -> Re: latch spining... in user mode or kernel mode ?
Connor McDonald <connor_mcdonald_at_yahoo.com> wrote:
>danisment wrote:
>>
>> Hi,
>>
>> I want to know how spinning is implemented on CPU . is it in kernel
>> mode, or user mode ?
>>
>> can we say following pseudo code is correct ?
>>
>> private int i = 0;
>> while (i < _SPIN_COUNT)
>> {
>> if (test_and_set(latch) == true) return true; // latch is acquired
>> here...
>> i++;
>> }
>>
>> Danisment Gazi Unal
>> http://www.unal-bilisim.com
>
>No, the spin is used to "pause" without relinquishing the cpu - we spin,
>and *then* try to get the latch.
This is not the case at all. Refer to the 8.0 docs, where spin_count was a documented parameter, or Note:30832.1. The behaviour hasn't changed significantly in 8i (or I'd guess 9i, but don't know) .
The algorithm is pretty much as above, with the addition of the sleep schedule, i.e. spin for _spin_count iterations of the loop, constantly trying to get the latch, relinquish CPU (but don't really sleep), spin again, then sleep on the latch wait event.
"
A process continues to request a latch until it obtains one. If the
number of requests reaches SPIN_COUNT, the process fails to acquire
the latch, sleeps, then tries to acquire the latch again. Because a
latch is a low-level lock, a process does not hold it long. It is less
expensive to use CPU time by spinning a process than it is to make a
process sleep.
" (8.0.3 Oracle Reference)
-- Andrew Mobbs - http://www.chiark.greenend.org.uk/~andrewm/Received on Mon Nov 19 2001 - 12:01:02 CST
![]() |
![]() |