← Back to index
|
Original Bugzilla link
Bug 21548 – Thread.getThis().id is 0
Status
NEW
Severity
critical
Priority
P2
Component
druntime
Product
D
Version
D2
Platform
x86_64
OS
Linux
Creation time
2021-01-14T12:20:15Z
Last change time
2024-12-07T13:40:55Z
Assigned to
No Owner
Creator
Adam Furtenbach
Moved to GitHub: dmd#17420 →
Attachments
ID
Filename
Summary
Content-Type
Size
1813
dlang_dump.txt
Several program invocations
text/plain
5364
Comments
Comment #0
by adam.furtenbach — 2021-01-14T12:20:15Z
Created attachment 1813 Several program invocations Assert in the following program sometimes hits. Throws core.thread.osthread.ThreadException@src/core/thread/osthread.d(867): Unable to join thread if assert() is removed. Tested on: 1) DMD64 D Compiler v2.090.1 2) DMD64 D Compiler v2.095.0 3) LDC - the LLVM D compiler (1.23.0): based on DMD v2.093.1 and LLVM 10.0.1 Fail in ~1 of 300 program invocations. (see attached file) import std.stdio; import std.container : SList; import core.thread; import std.stdio; import std.format; import core.sync.mutex; import core.sync.condition; import core.memory; public class Worker : Thread { private void delegate() _func; private ThreadedExecutor _executor; public this(void delegate() func, ThreadedExecutor executor) { super(&Run); _func = func; _executor = executor; } private void Run() { try { _func(); } catch (Throwable ex) { writeln(ex.msg); } _executor.Add(Thread.getThis()); } } public class ThreadedExecutor { private SList!Thread _expired; private Mutex _mutex; private Condition _condition; public this() { _mutex = new Mutex(); _condition = new Condition(_mutex); } public void Start() { auto thread = new Thread(&Reap); thread.start(); } public void Execute(void delegate() func) { auto thread = new Worker(func, this); thread.start(); } public void Add(Thread thread) { synchronized (_mutex) { _expired.insertFront(thread); _condition.notify(); } } private void Reap() { while (true) { synchronized (_mutex) { while (_expired.empty()) { _condition.wait(); } while (!_expired.empty()) { auto thread = _expired.front(); _expired.removeFront(); assert(thread.id != 0, "thread.id is zero..."); thread.join(); } } } } } void main() { GC.disable(); writeln(Thread.getThis().id); auto executor = new ThreadedExecutor(); void delegate() func = () {}; executor.Start(); executor.Execute(func); }
Comment #1
by robert.schadek — 2024-12-07T13:40:55Z
THIS ISSUE HAS BEEN MOVED TO GITHUB
https://github.com/dlang/dmd/issues/17420
DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB