Thread overview | |||||
---|---|---|---|---|---|
|
June 28, 2020 std.concurrency.receive and shared const(char)[]? | ||||
---|---|---|---|---|
| ||||
import std.stdio; import std.concurrency; void main() { auto t = spawn((){ receive((shared const(char)[] char_arr) { ownerTid.send(true); }); }); shared const(char)[] char_arr = "cut my code into pieces"; t.send(char_arr); assert(receiveOnly!(bool) == true); } When I run this program, it blocks on the receive() inside the spawned thread. What am I doing wrong? |
June 28, 2020 Re: std.concurrency.receive and shared const(char)[]? | ||||
---|---|---|---|---|
| ||||
Posted in reply to BakedPineapple | On Sunday, 28 June 2020 at 16:11:50 UTC, BakedPineapple wrote:
> import std.stdio;
> import std.concurrency;
>
> void main()
> {
> auto t = spawn((){
> receive((shared const(char)[] char_arr) {
> ownerTid.send(true);
> });
> });
> shared const(char)[] char_arr = "cut my code into pieces";
> t.send(char_arr);
> assert(receiveOnly!(bool) == true);
> }
>
> When I run this program, it blocks on the receive() inside the spawned thread. What am I doing wrong?
Make the parameter shared(const(char))[] and it will work. I'll leave it to someone who knows more to explain why it behaves that way.
|
June 28, 2020 Re: std.concurrency.receive and shared const(char)[]? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Anonymouse | On Sunday, 28 June 2020 at 16:39:12 UTC, Anonymouse wrote:
> On Sunday, 28 June 2020 at 16:11:50 UTC, BakedPineapple wrote:
>> import std.stdio;
>> import std.concurrency;
>>
>> void main()
>> {
>> auto t = spawn((){
>> receive((shared const(char)[] char_arr) {
>> ownerTid.send(true);
>> });
>> });
>> shared const(char)[] char_arr = "cut my code into pieces";
>> t.send(char_arr);
>> assert(receiveOnly!(bool) == true);
>> }
>>
>> When I run this program, it blocks on the receive() inside the spawned thread. What am I doing wrong?
>
> Make the parameter shared(const(char))[] and it will work. I'll leave it to someone who knows more to explain why it behaves that way.
ty.
|
Copyright © 1999-2021 by the D Language Foundation