| Thread overview | |||||||
|---|---|---|---|---|---|---|---|
|
March 08, 2014 Non-blocking array queue. | ||||
|---|---|---|---|---|
| ||||
Hi, I'm interesting in implementing a non-blocking queue. My thought is to use a fixed-size array, and increment back of the queue with a integer. I was thinking I could make this non-blocking via an atomic increment operation before assigning the pushed value onto the queue. So, my question is: How would you do an atomic increment in a cross-platform way in D? Thanks! -S. | ||||
March 08, 2014 Re: Non-blocking array queue. | ||||
|---|---|---|---|---|
| ||||
Posted in reply to Shammah Chancellor | On Saturday, 8 March 2014 at 19:02:26 UTC, Shammah Chancellor wrote: > Hi, > > I'm interesting in implementing a non-blocking queue. My thought is to use a fixed-size array, and increment back of the queue with a integer. I was thinking I could make this non-blocking via an atomic increment operation before assigning the pushed value onto the queue. So, my question is: How would you do an atomic increment in a cross-platform way in D? > > > Thanks! > -S. I think you could use http://dlang.org/phobos/core_atomic.html, maybe? | |||
March 08, 2014 Re: Non-blocking array queue. | ||||
|---|---|---|---|---|
| ||||
Posted in reply to Martin | On 2014-03-08 19:58:01 +0000, Martin said:
> On Saturday, 8 March 2014 at 19:02:26 UTC, Shammah Chancellor wrote:
>> Hi,
>>
>> I'm interesting in implementing a non-blocking queue. My thought is to use a fixed-size array, and increment back of the queue with a integer. I was thinking I could make this non-blocking via an atomic increment operation before assigning the pushed value onto the queue. So, my question is: How would you do an atomic increment in a cross-platform way in D?
>>
>>
>> Thanks!
>> -S.
>
> I think you could use http://dlang.org/phobos/core_atomic.html, maybe?
I didn't see a way to get an an increment operation. atomicOp doesn't seem to offer unitary operations.
-S.
| |||
March 08, 2014 Re: Non-blocking array queue. | ||||
|---|---|---|---|---|
| ||||
Posted in reply to Shammah Chancellor | On Saturday, 8 March 2014 at 21:12:42 UTC, Shammah Chancellor wrote:
> On 2014-03-08 19:58:01 +0000, Martin said:
>
>> On Saturday, 8 March 2014 at 19:02:26 UTC, Shammah Chancellor wrote:
>>> Hi,
>>>
>>> I'm interesting in implementing a non-blocking queue. My thought is to use a fixed-size array, and increment back of the queue with a integer. I was thinking I could make this non-blocking via an atomic increment operation before assigning the pushed value onto the queue. So, my question is: How would you do an atomic increment in a cross-platform way in D?
>>>
>>>
>>> Thanks!
>>> -S.
>>
>> I think you could use http://dlang.org/phobos/core_atomic.html, maybe?
>
> I didn't see a way to get an an increment operation. atomicOp doesn't seem to offer unitary operations.
>
> -S.
atomicOp!("+=")(value, 1);
Should work, I believe. Or is that not what you meant?
| |||
March 08, 2014 Re: Non-blocking array queue. | ||||
|---|---|---|---|---|
| ||||
Posted in reply to Martin | On 2014-03-08 21:16:36 +0000, Martin said:
> On Saturday, 8 March 2014 at 21:12:42 UTC, Shammah Chancellor wrote:
>> On 2014-03-08 19:58:01 +0000, Martin said:
>>
>>> On Saturday, 8 March 2014 at 19:02:26 UTC, Shammah Chancellor wrote:
>>>> Hi,
>>>>
>>>> I'm interesting in implementing a non-blocking queue. My thought is to use a fixed-size array, and increment back of the queue with a integer. I was thinking I could make this non-blocking via an atomic increment operation before assigning the pushed value onto the queue. So, my question is: How would you do an atomic increment in a cross-platform way in D?
>>>>
>>>>
>>>> Thanks!
>>>> -S.
>>>
>>> I think you could use http://dlang.org/phobos/core_atomic.html, maybe?
>>
>> I didn't see a way to get an an increment operation. atomicOp doesn't seem to offer unitary operations.
>>
>> -S.
>
> atomicOp!("+=")(value, 1);
>
> Should work, I believe. Or is that not what you meant?
I was considering using that, but in the channel I was told that would be inefficient assembly when it should normally be one operation?
| |||
Copyright © 1999-2021 by the D Language Foundation
Permalink
Reply