https://issues.dlang.org/show_bug.cgi?id=14934

Steven Schveighoffer <[email protected]> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|RESOLVED                    |REOPENED
                 CC|                            |[email protected]
         Resolution|WORKSFORME                  |---

--- Comment #3 from Steven Schveighoffer <[email protected]> ---
(In reply to Martin Nowak from comment #1)
> Please let's try to avoid arbitrary code execution with the GC lock held.

I really don't see another way to do this. Your idea of using
enterCriticalRegion isn't viable, because you need to call removeRange and
addRange (which take the lock, that might be held while attempting to suspend
the threads). Unless I misunderstand how it works.

However, I don't think it needs to be an "advertised" feature. I'm not sure we
need to do it via a delegate, all we need is exposure to the lock. This needs
to be done only in low-level situations.

> void* reallocImpl(void* p, size_t newSize)
> {
>   thread_enterCriticalRegion();
>   auto oldp = p;
>   p = realloc(p, newSize);
>   if (p !is oldp)
>   {
>       GC.removeRange(oldp);
>       GC.addRange(p, newSize);
>   }
>   thread_exitCriticalRegion();
>   return newPtr;
> }

Note, you need to remove and re-add the range in both cases, because the new
range is bigger.

--

Reply via email to