D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 6135 - Thread/GC interaction bug on OS X
Summary: Thread/GC interaction bug on OS X
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: x86 Mac OS X
: P2 major
Assignee: No Owner
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-06-09 13:36 UTC by David Nadlinger
Modified: 2011-07-20 21:59 UTC (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description David Nadlinger 2011-06-09 13:36:40 UTC
Consider the following program:
---
import core.memory;
import core.thread;

void doNothing() {}

void main() {
  foreach (i; 0 .. 10000) {
    auto t = new Thread(&doNothing);
    t.start();
    GC.collect();
  }
}
---

With latest DMD (9aae5c4) and druntime (00ce4ab) on OS X, this triggers the "Unable to load thread state" clause at core/thread.d:2280 during a GC collection (which in turn triggers an onOutOfMemoryError() on allocating the exception object because it happens during a GC runs, which accounts for #0-#5 in the backtrace below): 
---
#0  0x00012787 in _d_throwc ()
#1  0x00009686 in onOutOfMemoryError ()
#2  0x0000e8b9 in D2gc3gcx2GC12mallocNoSyncMFkkPkZPv ()
#3  0x0000e855 in D2gc3gcx2GC6mallocMFkkPkZPv ()
#4  0x0000dc58 in gc_malloc ()
#5  0x000134bb in _d_newclass ()
#6  0x0000b558 in D4core6thread17thread_suspendAllUZv7suspendMFC4core6thread6ThreadZv ()
#7  0x0000b447 in thread_suspendAll ()
#8  0x00010b75 in D2gc3gcx3Gcx11fullcollectMFPvZk ()
#9  0x00010b2d in D2gc3gcx3Gcx16fullcollectshellMFZk ()
#10 0x0000faf7 in D2gc3gcx2GC11fullCollectMFZk ()
#11 0x0000da59 in gc_collect ()
#12 0x000096bb in D4core6memory2GC7collectFZv ()
#13 0x000027ea in _Dmain ()
#14 0x000132df in D2rt6dmain24mainUiPPaZi7runMainMFZv ()
#15 0x00012e89 in D2rt6dmain24mainUiPPaZi7tryExecMFMDFZvZv ()
#16 0x00013327 in D2rt6dmain24mainUiPPaZi6runAllMFZv ()
#17 0x00012e89 in D2rt6dmain24mainUiPPaZi7tryExecMFMDFZvZv ()
#18 0x00012e23 in main ()
---
Comment 1 David Nadlinger 2011-06-09 13:55:00 UTC
The thread_get_state return code is 268435459 (0x10000003), probably corresponding to MACH_SEND_INVALID_DEST (mach/message.h). Just a shot in the dark, but maybe suspend() gets called for a thread that's no longer around?
Comment 2 David Nadlinger 2011-06-10 06:11:07 UTC
And indeed, t.isRunning is false when thread_get_state() is called.
Comment 4 Sean Kelly 2011-06-17 10:30:05 UTC
Reopened to be marked as fixed with the 2.054 release.
Comment 5 David Nadlinger 2011-07-20 21:59:06 UTC
Closing, again, as 2.054 has been released in the meantime.