Debugging silent exit of threads in Phobos calls

Steven Schveighoffer schveiguy at yahoo.com
Fri Jun 1 18:02:58 UTC 2018


On 6/1/18 1:41 PM, Russel Winder wrote:
> On Fri, 2018-06-01 at 18:30 +0100, Russel Winder wrote:
>> […]
>>
>> I'll trim this sample code down to the minimum so it can be used in
>> the
>> test suite of Phobos creating a red.
>>
> 
> Here it is, a small bit of code that breaks Phobos'
> std.concurrency.receive.
> 
> 
> import core.thread: Thread;
> import core.time: seconds;
> 
> import std.concurrency: Tid, OwnerTerminated, receive, receiveTimeout, send, spawn;
> import std.conv: to;
> import std.stdio: writeln;
> 
> struct Datum {
> 	public const int a;
> 	public const int b;
> }
> 
> struct Message {
> 	Datum datum;
> }
> 
> void sender(Tid receiver) {
> 	writeln("Sender sending.");
> 	receiver.send(Message(Datum(0, 0)));
> 	writeln("Sender finished.");
> }
> 
> void receiver() {
> 	writeln("Receiver going into receive.");
> 	try {
> 		receive(
> 			(Message message) {
> 				writeln("Receiver received  ", to!string(message));
> 			},
> 		);
> 	} catch (Throwable t) {
> 		writeln("Receiver receive threw " ~ to!string(t));
> 	}
> 	writeln("Receiver finished.");
> }
> 
> void mainloop() {
> 	Thread.sleep(2.seconds);
> }
> 
> int main() {
> 	auto receiver = spawn(&receiver);
> 	spawn(&sender, receiver);
> 	mainloop();
> 	return 0;
> }
> 
> 

Perfect, put this into a bugzilla entry. Most definitely it's a bug in 
phobos, it's clear from the assert(false, ...) which is NEVER meant to 
happen.

BTW, yes I was saying edit the global phobos sources :) I do this all 
the time to try and debug something. You just have to remember to put it 
back the way it was. In this case, you would just be printing something 
before crashing, so it actually could stay there.

One "nice" aspect of pretty much everything being a template.

-Steve


More information about the Digitalmars-d-learn mailing list