Skip to content

Added spawnRef and spawnLinkedRef for passing by reference through spawn#7167

Closed
ghost wants to merge 1 commit intodlang:masterfrom
e-archive56:spawnRef
Closed

Added spawnRef and spawnLinkedRef for passing by reference through spawn#7167
ghost wants to merge 1 commit intodlang:masterfrom
e-archive56:spawnRef

Conversation

@ghost
Copy link

@ghost ghost commented Sep 1, 2019

It is often useful to pass a mutable by reference type to the spawned
thread, the need to have to use a raw pointer before this patch made
the syntax boring and not in line with the rest of the DLang style
(use pointer as little as possible).

With this patch it will be possible to write code like this:

import std.concurrency : spawnRef;
import core.atomic : atomicOp;
import core.thread : thread_joinAll;

static void f1(ref shared(int) number)
{
  atomicOp!"+="(number, 1);
}

shared(int) number = 10;
spawnRef(&f1, number);
thread_joinAll();
assert(number == 11);

Instead of the boring:

import std.concurrency : spawn;
import core.atomic : atomicOp;
import core.thread : thread_joinAll;

static void f1(ref shared(int)* number)
{
  atomicOp!"+="(*number, 1);
}

shared(int) number = 10;
spawn(&f1, &number);
thread_joinAll();
assert(number == 11);

This PR is an alternative of #7124

@ghost ghost force-pushed the spawnRef branch 2 times, most recently from 1b6d33b to ff1ad47 Compare September 1, 2019 23:04
It is often useful to pass a mutable by reference type to the spawned
thread, the need to have to use a raw pointer before this patch made
the syntax boring and not in line with the rest of the DLang style
(use pointer as little as possible).

Signed-off-by: Ernesto Castellotti <erny.castell@gmail.com>
@ghost ghost marked this pull request as ready for review September 2, 2019 07:41
@ghost ghost requested a review from MartinNowak as a code owner September 2, 2019 07:41
@atilaneves
Copy link
Contributor

As mentioned in the other PR, I'm not sure of this at all.

@ghost
Copy link
Author

ghost commented Sep 3, 2019

I don't know, everyone does not like the previous PR and currently does not pass all the tests yet

@atilaneves
Copy link
Contributor

I don't know, everyone does not like the previous PR and currently does not pass all the tests yet

I'd been previously miffed by not being able to use spawn with ref functions, so I like the premise of it. A separate function that uses ref is not something I think is useful and, at this point, unlikely to convince me to add to Phobos.

@RazvanN7
Copy link
Collaborator

@ErnyTech @atilaneves How should we move forward here? Should we close this?

@atilaneves
Copy link
Contributor

Is there a reason why it has to have a different name?

@ghost
Copy link
Author

ghost commented Apr 21, 2021

Sorry but currently I can no longer take care of this, I think it is better to close this.

If someone else intends to continue they can open a new PR

@RazvanN7
Copy link
Collaborator

Filed: https://issues.dlang.org/show_bug.cgi?id=21848

Closing.

@RazvanN7 RazvanN7 closed this Apr 22, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants