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 by code — 2011-06-09T13:55:00Z
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 by code — 2011-06-10T06:11:07Z
And indeed, t.isRunning is false when thread_get_state() is called.