Thin Lock Implementation

Sean Kelly sean at invisibleduck.org
Wed Aug 20 12:56:01 PDT 2008


BCS wrote:
> Reply to Walter,
> 
>> Walter Bright wrote:
>>
>>> BCS wrote:
>>>
>>>>> The memory isn't committed until it is used, but the address space
>>>>> is. You cannot move the stack if it exceeds its preallocated
>>>>> address space allotment.
>>>>>
>>>> Must the stack be contiguous? Could you, on a stack overflow, heap
>>>> allocate a new chunk and put in a frame that gets back to the last
>>>> segment?
>>>>
>>> No.
>>>
>> I suppose I should explain a bit more. Stack overflows are detected by
>> the hardware, which means every PUSH could overflow the stack. It
>> isn't practical to then try and continue the stack elsewhere, because
>> the corresponding POPs would not know what was going on.
>>
> 
> That's what the extra stack frame I mentioned is for. I'll grant you 
> can't split a single frame across the sections but if you cold detect an 
> impending stack overflow before the function runs (by push/popping the 
> largest block that the function can use [calloc aside]) you could then 
> do the new stack at that point. When the function returns, it ends up in 
> the extra frame and it knows how to return to the right location.

This is basically how Fibers work, though the stack transition isn't 
invisible.  Each Fiber has its own stack and execution is transferred to 
some location in this stack when the Fiber is called.


Sean



More information about the Digitalmars-d mailing list