Skip to content
This repository has been archived by the owner on Oct 12, 2022. It is now read-only.

fix Issue 15822 - InvalidMemoryOperationError when calling GC.removeRange/Root from a finalizer #1519

Merged
merged 1 commit into from
Mar 23, 2016

Conversation

MartinNowak
Copy link
Member

  • use separate locks for GC.add/removeRange/Root
  • avoids GC.lock contention for manual memory management

…ange/Root from a finalizer

- use separate locks for GC.add/removeRange/Root
- avoids GC.lock contention for manual memory management
@dlang-bot
Copy link
Contributor

Fix Bugzilla Description
15822 InvalidMemoryOperationError when calling GC.removeRange/Root from a finalizer

@WalterBright
Copy link
Member

Auto-merge toggled on

@WalterBright WalterBright merged commit c6ac077 into dlang:stable Mar 23, 2016
@MartinNowak MartinNowak deleted the fix15822 branch March 23, 2016 12:18
@DmitryOlshansky
Copy link
Member

Wouldn't this deadlock in situation where:

  1. thread A calls addRange and takes the "add range" lock
  2. thread B starts GC collection
  3. Some finalizer calls removeRange

@rainers
Copy link
Member

rainers commented Mar 23, 2016

Should be ok because finalizers are run in the sweep phase, but the locks are only held during marking.

@MartinNowak
Copy link
Member Author

thread A calls addRange and takes the "add range" lock
thread B starts GC collection

A deadlock can happen if you have a possible lock-order inversion or more generally a cycle in the lock-order graph.
Let's see.

rootsLock -> mallocLocks
rangesLock -> mallocLocks
gcLock -> rootsLock -> mmap (no other locks during marking)
gcLock -> rangesLock -> mmap (no other locks during marking)

Threads aren't suspended while holding the locks. Looks fine.
In particular it would still allow for parallel/asynchronous finalization.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants