HaxeFoundation / HaxeFoundation/hxcpp

PauseForCollect may cause the GC to freeze.

Open
#947 23 comments 2 reactions 0 assignees View on GitHub
Dominant language
C++
Stars
330
Forks
227
Avg merge
2d 16h
Merged PRs (30d)
18

Description

```
void PauseForCollect()
{
if (sgIsCollecting)
CriticalGCError("Bad Allocation while collecting - from finalizer?");
#ifndef HXCPP_SINGLE_THREADED_APP
volatile int dummy = 1;
mBottomOfStack = (int *)&dummy;
CAPTURE_REGS;
#ifdef VerifyStackRead
VerifyStackRead(mBottomOfStack, mTopOfStack)
#endif

mReadyForCollect.Set();
```

** THE COLLECT PROCESS STARTS NOW, AND IF IT FINISHES BEFORE IT REACHES THE NEXT LINE THE PROCESS
IS STUCK **

```
mCollectDone.Wait();
#endif
}
```

My solution. Remove mCollectDone semaphore. Remove ReleaseFromSafe. Replace PauseFor Collect with this code:

```
void PauseForCollect()
{
if (sgIsCollecting)
CriticalGCError("Bad Allocation while collecting - from finalizer?");

#ifndef HXCPP_SINGLE_THREADED_APP
EnterGCFreeZone();
gThreadStateChangeLock->Lock();
ExitGCFreeZoneLocked();

gThreadStateChangeLock->Unlock();
#endif
}
```

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.