[Issue 19313] New: Attaching external thread may result in segfault
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Fri Oct 19 12:57:52 UTC 2018
https://issues.dlang.org/show_bug.cgi?id=19313
Issue ID: 19313
Summary: Attaching external thread may result in segfault
Product: D
Version: D2
Hardware: All
OS: All
Status: NEW
Severity: normal
Priority: P1
Component: druntime
Assignee: nobody at puremagic.com
Reporter: mihails.strasuns at gmail.com
Split from https://issues.dlang.org/show_bug.cgi?id=19288 as on of sub-issues
Essence of the issue:
```
import core.sys.posix.pthread;
import core.memory;
extern(C)
void* entry_point(void*)
{
// in real world case this may be called through `thread_attachThis`:
GC.collect();
return null;
}
void main()
{
// ensure some garbage exists
auto x = new int[1000];
pthread_t thread;
auto status = pthread_create(&thread, null, &entry_point, null);
assert(status == 0);
pthread_join(thread, null);
}
```
Same applies to other operating systems. Problems comes from the fact that GC
implementation is not ready for `Thread.getThis()` to be `null` and will crash
in several places if this happens. And because `thread_attachThis` has to call
`new Thread` to allocate new context, collection may happen before thread is
actually registered.
--
More information about the Digitalmars-d-bugs
mailing list