digitalmars.D.learn - Fiber and Thread Communication
- =?UTF-8?B?Tm9yZGzDtnc=?= (6/6) Apr 08 2016 Are there any plans to unite
- Dicebot (3/9) Apr 08 2016 Doesn't std.concurrency support both right now? I remember seeing
- =?UTF-8?B?Tm9yZGzDtnc=?= (3/5) Apr 08 2016 1. What functions provide message box communication?
- Dicebot (7/12) Apr 08 2016 See https://issues.dlang.org/show_bug.cgi?id=12090 and
- =?UTF-8?B?Tm9yZGzDtnc=?= (2/15) Apr 08 2016 So a TId can represent either a thread or a fiber?
- Dicebot (3/4) Apr 08 2016 AFAIR, yes (I haven't used std.concurrency in a long while,
- tcak (6/10) Apr 08 2016 yes what? Thread or Fiber.
- Dicebot (3/10) Apr 08 2016 Yes both :) Tid represent abstract execution context, with no
- =?UTF-8?Q?Ali_=c3=87ehreli?= (6/17) Apr 08 2016 Thanks Dicebot. I don't think the included
- Dicebot (4/23) Apr 08 2016 Looks like a (funny) oversight. Note that you get it for get
- =?UTF-8?Q?Ali_=c3=87ehreli?= (58/71) Apr 09 2016 https://github.com/D-Programming-Language/phobos/blob/master/std/concurr...
- Alex Parrill (4/5) Apr 08 2016 It represents a "logical thread", which currently consists of
- =?UTF-8?B?Tm9yZGzDtnc=?= (3/5) Apr 08 2016 What progress has been since post:
- =?UTF-8?B?Tm9yZGzDtnc=?= (14/15) Apr 09 2016 AFAICT, it is not clear what are the limitations of the current
- =?UTF-8?Q?Ali_=c3=87ehreli?= (5/10) Apr 09 2016 I don't know how much this helps but I was able to write an example that...
Are there any plans to unite fiber-to-fiber communication with thread-to-thread communication in Phobos? Does vibe.d give any solutions here?
Apr 08 2016
On Friday, 8 April 2016 at 10:51:49 UTC, Nordlöw wrote:Are there any plans to unite fiber-to-fiber communication with thread-to-thread communication in Phobos? Does vibe.d give any solutions here?Doesn't std.concurrency support both right now? I remember seeing PR that adds message box support to fibers ages ago.
Apr 08 2016
On Friday, 8 April 2016 at 11:01:21 UTC, Dicebot wrote:Doesn't std.concurrency support both right now? I remember seeing PR that adds message box support to fibers ages ago.1. What functions provide message box communication? 2. But Fibers cannot currently be moved between threads right?
Apr 08 2016
On Friday, 8 April 2016 at 11:18:11 UTC, Nordlöw wrote:On Friday, 8 April 2016 at 11:01:21 UTC, Dicebot wrote:See https://issues.dlang.org/show_bug.cgi?id=12090 and https://github.com/D-Programming-Language/phobos/pull/1910 for relevant code (as you can see it was merged several releases ago)Doesn't std.concurrency support both right now? I remember seeing PR that adds message box support to fibers ages ago.1. What functions provide message box communication?The same ones as thread ones. API is completely transparent.2. But Fibers cannot currently be moved between threads right?Yes, and this is by design. It harms performance of concurrent apps.
Apr 08 2016
On Friday, 8 April 2016 at 13:15:07 UTC, Dicebot wrote:On Friday, 8 April 2016 at 11:18:11 UTC, Nordlöw wrote:So a TId can represent either a thread or a fiber?On Friday, 8 April 2016 at 11:01:21 UTC, Dicebot wrote:See https://issues.dlang.org/show_bug.cgi?id=12090 and https://github.com/D-Programming-Language/phobos/pull/1910 for relevant code (as you can see it was merged several releases ago)Doesn't std.concurrency support both right now? I remember seeing PR that adds message box support to fibers ages ago.1. What functions provide message box communication?The same ones as thread ones. API is completely transparent.2. But Fibers cannot currently be moved between threads right?Yes, and this is by design. It harms performance of concurrent apps.
Apr 08 2016
On Friday, 8 April 2016 at 14:08:39 UTC, Nordlöw wrote:So a TId can represent either a thread or a fiber?AFAIR, yes (I haven't used std.concurrency in a long while, telling all from memory only).
Apr 08 2016
On Friday, 8 April 2016 at 15:33:46 UTC, Dicebot wrote:On Friday, 8 April 2016 at 14:08:39 UTC, Nordlöw wrote:yes what? Thread or Fiber. --- Anyway. Since, Fiber is not like a thread, and when a thread starts a Fiber, it is like calling a normal function, I guess TId represents the thread still.So a TId can represent either a thread or a fiber?AFAIR, yes (I haven't used std.concurrency in a long while, telling all from memory only).
Apr 08 2016
On Friday, 8 April 2016 at 19:46:17 UTC, tcak wrote:On Friday, 8 April 2016 at 15:33:46 UTC, Dicebot wrote:Yes both :) Tid represent abstract execution context, with no implications about underlying executor.On Friday, 8 April 2016 at 14:08:39 UTC, Nordlöw wrote:yes what? Thread or Fiber.So a TId can represent either a thread or a fiber?AFAIR, yes (I haven't used std.concurrency in a long while, telling all from memory only).
Apr 08 2016
On 04/08/2016 01:16 PM, Dicebot wrote:On Friday, 8 April 2016 at 19:46:17 UTC, tcak wrote:Thanks Dicebot. I don't think the included std.concurrency.FiberScheduler has support for message passing because FiberScheduler.spawn does not return a Tid. If so, I don't see how it's possible to send messages between fibers. AliOn Friday, 8 April 2016 at 15:33:46 UTC, Dicebot wrote:Yes both :) Tid represent abstract execution context, with no implications about underlying executor.On Friday, 8 April 2016 at 14:08:39 UTC, Nordlöw wrote:yes what? Thread or Fiber.So a TId can represent either a thread or a fiber?AFAIR, yes (I haven't used std.concurrency in a long while, telling all from memory only).
Apr 08 2016
On Friday, 8 April 2016 at 20:25:11 UTC, Ali Çehreli wrote:On 04/08/2016 01:16 PM, Dicebot wrote:Looks like a (funny) oversight. Note that you get it for get fiber via https://github.com/D-Programming-Language/phobos/blob/master/std concurrency.d#L1337 (and FiberScheduler specifically extends Fiber to add ThreadInfo to it) but there is no clear way to pass that info to spawn host. I have a feeling that if that code is patched to simply provide Tid, message passing will just magically work. Needs to be checked though.On Friday, 8 April 2016 at 19:46:17 UTC, tcak wrote:Thanks Dicebot. I don't think the included std.concurrency.FiberScheduler has support for message passing because FiberScheduler.spawn does not return a Tid. If so, I don't see how it's possible to send messages between fibers. AliOn Friday, 8 April 2016 at 15:33:46 UTC, Dicebot wrote:Yes both :) Tid represent abstract execution context, with no implications about underlying executor.On Friday, 8 April 2016 at 14:08:39 UTC, Nordlöw wrote:yes what? Thread or Fiber.So a TId can represent either a thread or a fiber?AFAIR, yes (I haven't used std.concurrency in a long while, telling all from memory only).
Apr 08 2016
On 04/08/2016 02:42 PM, Dicebot wrote:Sorry, I misled you. :)Thanks Dicebot. I don't think the included std.concurrency.FiberScheduler has support for message passing because FiberScheduler.spawn does not return a Tid. If so, I don't see how it's possible to send messages between fibers. AliLooks like a (funny) oversight.Note that you get it for get fiber viahttps://github.com/D-Programming-Language/phobos/blob/master/std concurrency.d#L1337(and FiberScheduler specifically extends Fiber to add ThreadInfo to it) but there is no clear way to pass that info to spawn host. I have a feeling that if that code is patched to simply provide Tid, message passing will just magically work. Needs to be checked though.It turns out, instead of calling scheduler.spawn() directly, the program sets the __gshared 'scheduler' variable first and then calls spawn() as usual, which does return that fiber's Tid: import std.stdio; import std.concurrency; import std.range; import std.algorithm; struct Done { } void workerTask(int id) { writefln("workerTask %s started", id); bool done = false; while (!done) { receive( (int message) { writefln("workerTask %s received %s", id, message); ownerTid.send(message * id); }, (Done message) { writefln("workerTask %s received Done", id); done = true; }); // Seems not to be needed: // scheduler.yield(); } writefln("workerTask %s exiting", id); } void mainTask() { enum workerCount = 5; enum loopCount = 3; writeln("mainTask started"); auto workers = iota(workerCount) .map!(id => spawn(&workerTask, id)) .array; foreach (i; 0 .. loopCount) { foreach (id, worker; workers) { worker.send(i); auto response = receiveOnly!int(); assert(response == i * id); writefln("mainTask received %s", response); } } writeln("mainTask sending Done messages"); foreach (worker; workers) { worker.send(Done()); } writeln("mainTask exiting"); } void main() { scheduler = new FiberScheduler; scheduler.start({ mainTask(); }); } Ali
Apr 09 2016
On Friday, 8 April 2016 at 14:08:39 UTC, Nordlöw wrote:So a TId can represent either a thread or a fiber?It represents a "logical thread", which currently consists of coroutines or OS threads but could theoretically be extended to, say, other processes or even other machines.
Apr 08 2016
On Friday, 8 April 2016 at 11:01:21 UTC, Dicebot wrote:Doesn't std.concurrency support both right now? I remember seeing PR that adds message box support to fibers ages ago.What progress has been since post: http://forum.dlang.org/post/k4jsef$26h6$1 digitalmars.com
Apr 08 2016
On Friday, 8 April 2016 at 10:51:49 UTC, Nordlöw wrote:Are there any plans to uniteAFAICT, it is not clear what are the limitations of the current std.concurrency and, from what. An illustrating example on task-based parallellism (such as the ones in jin.go) should partly alleviate this problem. Any ideas on what such an example should contain and illustrate. Current limitations and plans on fixing should be described aswell. References: http://forum.dlang.org/post/mailman.776.1459177268.26339.digitalmars-d puremagic.com http://code.dlang.org/packages/jin-go https://github.com/nin-jin/go.d Further, who's up for the job of add the missing parts in std.concurrency using ideas and code from https://github.com/nin-jin/go.d ? :)
Apr 09 2016
On 04/09/2016 07:45 AM, Nordlöw wrote:On Friday, 8 April 2016 at 10:51:49 UTC, Nordlöw wrote:AFAICT, it is not clear what are the limitations of the current std.concurrency and, from what. An illustrating example on task-based parallellism (such as the ones in jin.go) should partly alleviate this problem.I don't know how much this helps but I was able to write an example that seems to work (elsewhere in this thread): http://forum.dlang.org/post/nec62k$26v7$1 digitalmars.com Ali
Apr 09 2016