D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 6587 - std.parallelism's Task cannot handle immutable values
Summary: std.parallelism's Task cannot handle immutable values
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: phobos (show other issues)
Version: D2
Hardware: All All
: P2 normal
Assignee: No Owner
URL:
Keywords:
Depends on: 6588
Blocks:
  Show dependency treegraph
 
Reported: 2011-08-31 22:34 UTC by Andrew Wiley
Modified: 2014-02-15 02:46 UTC (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Andrew Wiley 2011-08-31 22:34:42 UTC

    
Comment 1 Andrew Wiley 2011-08-31 22:39:40 UTC
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 David Simcha 2011-09-01 06:38:52 UTC
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 David Simcha 2011-09-03 08:24:38 UTC
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 David Simcha 2012-01-12 20:32:11 UTC
This has been fixed for a few releases.  Closing.