Passing Command Line Arguments to a new Thread

via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Thu Aug 7 11:38:36 PDT 2014


On Thursday, 7 August 2014 at 18:33:40 UTC, H. S. Teoh via 
Digitalmars-d-learn wrote:
> On Thu, Aug 07, 2014 at 06:23:24PM +0000, "Nordlöw" via 
> Digitalmars-d-learn wrote:
>> What is the best way to forward a string[] as argument to a 
>> function
>> called through std.concurrency.spawn().
>> 
>> I need this in the following example where I start the vibe.d 
>> event
>> loop in the main thread (the only way I've managed to get
>> runEventLoop() to work) and run my other program logic in 
>> another
>> which requires command line arguments to passed to the new 
>> thread.
>> 
>> void otherMain(string[] args)
>> {
>>     // use args
>> }
>> 
>> void main(string[] args)
>> {
>>     import std.concurrency: spawn;
>>     auto otherMainTid = spawn(&otherMain, args); // this line 
>> fails
>>     runEventLoop();
>> }
>> 
>> The line calling spawn() fails as
>> 
>> /home/per/opt/x86_64-unknown-linux-gnu/dmd/linux/bin64/src/phobos/std/concurrency.d(442):
>> Error: static assert  "Aliases to mutable thread-local data 
>> not allowed."
>
> Maybe try args.idup instead?

But this shouldn't be necessary, right? It's a mutable slice to 
immutable data, but the slice is passed by value, so no mutable 
sharing takes place.


More information about the Digitalmars-d-learn mailing list