Feature Request (for 1.0 as well): add a way to override the GC-perceived top of the stack

naryl cy at ngs.ru
Fri Jan 11 10:19:18 PST 2008


On Fri, 11 Jan 2008 20:36:24 +0300, Robert Fraser  
<fraserofthenight at gmail.com> wrote:

> downs wrote:
>> The Phobos GC presumes a linear stack that stretches from <bottom> to  
>> the current ESP.
>>  This model is normally correct; however, the virtual stacks used in  
>> StackThreads or similar
>> models kinda break it.
>>
>>> Illustration:
>>>
>>>   Normal stack:
>>>
>>> [bottom]=====================================[ESP]
>>>
>>>
>>>   StackThreads stack:
>>>
>>> [bottom]=========|==========[End]    
>>> [Heap================================================= ... ]
>>>                  |
>>>                  +.....................[Virtual stack  
>>> bottom]====================[ESP]
>>>
>>  This is easy to fix; introduce a new Thread function (getStackTop)  
>> that checks if a Thread member
>> variable (void *overrideStackTop) is set; if yes, return that variable,  
>> otherwise return getESP().
>>  Since this is a rather smallish correction that doesn't require any  
>> API change, I'd greatly welcome it
>> if this change was applied to 1.0, since because of the way the current  
>> GC works, writing reliable
>> StackThreads is essentially impossible.
>>  Thanks for your consideration,
>>   --downs
>
> Wouldn't this add the overhead of a function call to every collect cycle?

Collect cycles are not so frequent for this to be a problem. Only if  
program allocates and frees a lot (like 1GB per second) of memory or has  
1000 threads.



More information about the Digitalmars-d mailing list