Bug 6126 – std.parallelism does not re-throw exception

Status
RESOLVED
Resolution
INVALID
Severity
normal
Priority
P2
Component
phobos
Product
D
Version
D2
Platform
Other
OS
Mac OS X
Creation time
2011-06-08T13:17:00Z
Last change time
2011-06-08T19:30:43Z
Assigned to
dsimcha
Creator
robert

Comments

Comment #0 by robert — 2011-06-08T13:17:51Z
The following code: ---- import std.exception; import std.parallelism; void foo(int task) { enforce(task != 4); } void main() { int[] tasks = [1, 2, 3]; taskPool.put(task!foo(4)); foreach (task; taskPool.parallel(tasks)) { foo(task); } } ---- Does not re-throw the exception when the task uses .put() then .parallel() is used to run the tasks. Changing the enforcement to == causes three exceptions to be thrown as expected.
Comment #1 by dsimcha — 2011-06-08T19:30:43Z
Exceptions thrown from within tasks are re-thrown when you call done(), workForce(), yieldForce(), or spinForce() on the Task object. You created an anonymous task and never called any of these functions. The following slightly modified code does re-throw the exception. import std.exception; import std.parallelism; void foo(int task) { enforce(task != 4); } void main() { int[] tasks = [1, 2, 3]; auto t = task!foo(4); taskPool.put(t); foreach (task; taskPool.parallel(tasks)) { foo(task); } t.yieldForce(); }