Thread overview | |||||
---|---|---|---|---|---|
|
September 02, 2016 Fiber cross threads terminated | ||||
---|---|---|---|---|
| ||||
Here's my code in main function: ``` auto fiber = new Fiber({ while (true) { Thread.sleep(1.seconds); Fiber.yield; } }); void foo() { while (true) { fiber.call; //Thread.sleep(1.seconds); //"---".writeln; } } new Thread({ foo(); }).start; new Thread({ Thread.sleep(500.msecs); foo(); }).start; ``` If I comment the `fiber.call;`, all works. system: ubuntu 16.04LTS dmd version: 2.071.1 |
September 01, 2016 Re: Fiber cross threads terminated | ||||
---|---|---|---|---|
| ||||
Posted in reply to mogu | On 9/1/16 9:27 PM, mogu wrote:
> Here's my code in main function:
> ```
> auto fiber = new Fiber({
> while (true) {
> Thread.sleep(1.seconds);
> Fiber.yield;
> }
> });
>
> void foo() {
> while (true) {
> fiber.call;
> //Thread.sleep(1.seconds);
> //"---".writeln;
> }
> }
>
> new Thread({
> foo();
> }).start;
>
> new Thread({
> Thread.sleep(500.msecs);
> foo();
> }).start;
>
> ```
> If I comment the `fiber.call;`, all works.
> system: ubuntu 16.04LTS
> dmd version: 2.071.1
Fibers in D are not meant to be run in multiple threads.
-Steve
|
September 02, 2016 Re: Fiber cross threads terminated | ||||
---|---|---|---|---|
| ||||
Posted in reply to Steven Schveighoffer | On Friday, 2 September 2016 at 01:53:58 UTC, Steven Schveighoffer wrote:
> On 9/1/16 9:27 PM, mogu wrote:
>> Here's my code in main function:
>> ```
>> auto fiber = new Fiber({
>> while (true) {
>> Thread.sleep(1.seconds);
>> Fiber.yield;
>> }
>> });
>>
>> void foo() {
>> while (true) {
>> fiber.call;
>> //Thread.sleep(1.seconds);
>> //"---".writeln;
>> }
>> }
>>
>> new Thread({
>> foo();
>> }).start;
>>
>> new Thread({
>> Thread.sleep(500.msecs);
>> foo();
>> }).start;
>>
>> ```
>> If I comment the `fiber.call;`, all works.
>> system: ubuntu 16.04LTS
>> dmd version: 2.071.1
>
> Fibers in D are not meant to be run in multiple threads.
>
> -Steve
Thanks. I got it.
|
Copyright © 1999-2021 by the D Language Foundation