Debugging silent exit of threads in Phobos calls

Russel Winder russel at winder.org.uk
Fri Jun 1 17:41:30 UTC 2018


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;
}


-- 
Russel.
===========================================
Dr Russel Winder      t: +44 20 7585 2200
41 Buckmaster Road    m: +44 7770 465 077
London SW11 1EN, UK   w: www.russel.org.uk
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: This is a digitally signed message part
URL: <http://lists.puremagic.com/pipermail/digitalmars-d-learn/attachments/20180601/1caa93ff/attachment.sig>


More information about the Digitalmars-d-learn mailing list