Bug 6587 – std.parallelism's Task cannot handle immutable values

Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P2
Component
phobos
Product
D
Version
D2
Platform
All
OS
All
Creation time
2011-08-31T22:34:00Z
Last change time
2014-02-15T02:46:40Z
Assigned to
nobody
Creator
debio264
Depends on
6588

Comments

Comment #0 by debio264 — 2011-08-31T22:34:42Z
Comment #1 by debio264 — 2011-08-31T22:39:40Z
When creating Tasks to run on a TaskPool using std.parallelism, it looks like I can't call functions that have immutable objects: code: import std.parallelism; class Test { } void doSomething(immutable(Test) test) { } void main() { immutable(Test) test = new immutable(Test)(); taskPool().put(task!(doSomething)(test)); } compiler output: Error: can only initialize const member __args_field_0 inside constructor Error: this is not mutable /usr/include/d2/4.6.0/std/parallelism.d:734: Error: template instance std.parallelism.Task!(doSomething,immutable(Test)) error instantiating tasktest.d:11: instantiated from here: task!(doSomething,immutable(Test)) Is this something that can be fixed, or does this depend on having tail const support (which would hopefully work for immutable as well)? This use case seems particularly important as immutability is the simplest way to ensure safe multithreading.
Comment #2 by dsimcha — 2011-09-01T06:38:52Z
This should work, but I had neglected to put a test in for it. Anyhow, the underlying reason it doesn't work is Bug 6588.
Comment #3 by dsimcha — 2011-09-03T08:24:38Z
I found a workaround for 6588 and put it into a larger pull request with various improvements to std.parallelism: https://github.com/D-Programming-Language/phobos/pull/217
Comment #4 by dsimcha — 2012-01-12T20:32:11Z
This has been fixed for a few releases. Closing.