Use of mutex in destructors

Simen Kjaeraas simen.kjaras at gmail.com
Fri Apr 27 06:29:29 PDT 2012


On Fri, 27 Apr 2012 14:57:52 +0200, Rene Zwanenburg  
<renezwanenburg at gmail.com> wrote:

> On Friday, 27 April 2012 at 11:53:37 UTC, Simen Kjaeraas wrote:
>> On Fri, 27 Apr 2012 13:23:00 +0200, Dmitry Olshansky  
>> <dmitry.olsh at gmail.com> wrote:
>>
>>> On 27.04.2012 15:15, Rene Zwanenburg wrote:
>>>> Since an OpenGL context is owned by one thread, any OpenGL calls made
>>>> from other threads will fail. I've wrapped OpenGL 'objects' in D  
>>>> classes
>>>> to automate destruction of the underlying object:
>>>>
>>> How about using structs for GL objects? It's not like you have a  
>>> hierarchy or interfaces in there.
>>>
>>> [snip]
>>>
>>
>> http://d.puremagic.com/issues/show_bug.cgi?id=2834
>>
>> Heap-allocated structs don't have their destructors called when they're  
>> collected.
>
> Good to know, that's quite a serious bug and is open for three years  
> now. Is it that hard to fix?

It's not necessarily hard to fix, but the simple fixes are costly in other
ways - allocate a tag block for each alloation or adjust some data  
structure
in the GC to point to the destructor - each of these makes allocation
slower, which is unacceptable to some (I'm just allocating POD struct! Why
do I have to pay so that guy over there can have his data destroyed in an
orderly manner?)

But as Steve said, there is work on a precise GC that will likely fix the
problem.


More information about the Digitalmars-d-learn mailing list