Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
wants to merge 1 commit into from

Conversation

ErnyTech
Copy link

@ErnyTech ErnyTech 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

@ErnyTech ErnyTech 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>
@atilaneves
Copy link
Contributor

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

@ErnyTech
Copy link
Author

ErnyTech 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?

@ErnyTech
Copy link
Author

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.

3 participants