开发者

Wait-free buffer filling algorithm

开发者 https://www.devze.com 2023-03-13 01:07 出处:网络
I have a buffer of constant width N which is filled by several processes from both ends - each process can at one moment push L elements to the leftmost empty positions or R elements to the rightmost

I have a buffer of constant width N which is filled by several processes from both ends - each process can at one moment push L elements to the leftmost empty positions or R elements to the rightmost empty positions. I synchronize the processes on two variables (left stack top and right stack top) using the CAS instruction.

It is guaranteed that the buffer will not overflow, in fact space for one element between the stacks tops will be left. What I need is that one and only one of these processes will report the position of this empty space.

Originally I had to push both on the left and right side in the end, so after pushing to the left and then to the right the process could look on the left stack top, compare it + 1 to the position of its last right push and if these two were equal, the process was the last one (the last process pushing to the right when the buffer is filled wins). However, now I've realized I cannot guarantee pushing on both sides in the end so this protocol cannot be applied.

Can you think of any wait-free protocol that would suffice? I can use more variables with the CAS instruction, but I cannot atomically modify or read more than one at one moment. Of course, the less v开发者_如何学JAVAariables the better.

0

精彩评论

暂无评论...
验证码 换一张
取 消