Conversation
example/LockFreeQueue.chpl
Outdated
| * Created by Garvit Dewan - | ||
| * https://github.com/dgarvit/epoch-based-manager/blob/master/src/LockFreeQueue.chpl | ||
| * | ||
| * Lock-Free Queue that uses ABA feature of Distributed Data Structures |
There was a problem hiding this comment.
Should probably say that it uses the ABA feature of LocalAtomicObject. Sure the LocalAtomicObject was created back in GSoC 2017, but you don't need to state that here.
example/LockFreeQueue.chpl
Outdated
|
|
||
| proc init(type eltType) { | ||
| this.eltType = eltType; | ||
| val = nil; |
There was a problem hiding this comment.
Do not initialize val with a value, leave it as is (it will be initialized to a default value automatically). If eltType is an integral (int,uint, etc.), a tuple or a record, this will result in a compiler error.
There was a problem hiding this comment.
Well, I think that would further require changes to peek() and dequeue() in terms that if queue is empty then cannot return nil for eltType int
example/LockFreeQueue.chpl
Outdated
| var curr_head = _head.readABA(); | ||
| var curr_tail = _tail.readABA(); | ||
| var next = curr_head.next.readABA(); | ||
| if (_head.read() == _tail.read()) { |
There was a problem hiding this comment.
Why do you read curr_head and curr_tail and then try to read them again? Are you sure you shouldn't do curr_head.getObject() == curr_tail.getObject()?
There was a problem hiding this comment.
My bad, fixed it. Thanks for pointing out!
| } | ||
|
|
||
| iter these() : objType { | ||
| var ptr = _head.read().next.read(); |
There was a problem hiding this comment.
What happens if the queue is empty?
There was a problem hiding this comment.
When queue is empty, it will hold a dummy node, which will have a next, which will be a LocalAtomicObject, which will point to a nil value.
There was a problem hiding this comment.
So, nothing will happen, because, if ptr is nil. then the function will finish executing.
There was a problem hiding this comment.
Right, I forgot about the dummy node! That should work then.
example/LockFreeQueue.chpl
Outdated
| } | ||
|
|
||
| proc peek() : objType { | ||
| return _head.read().next.read().val; |
There was a problem hiding this comment.
What happens if the queue is empty?
There was a problem hiding this comment.
Similar to the previous reason, this will return nil. There was a bug with it, which I have fixed now.
| var ptr = _head.read(); | ||
| while (ptr != nil) { | ||
| _head = ptr.next; | ||
| delete ptr.val; |
There was a problem hiding this comment.
Nope, don't assume the user will have classes. If they want to have their classes managed, they should use a shared or owned type.
| } | ||
| } | ||
| } | ||
| } |
There was a problem hiding this comment.
Add a main function here that tests it, similar to what is done in LockFreeStack.chpl:
LocalAtomics/example/LockFreeStack.chpl
Lines 75 to 80 in 614410c
|
Can you also make Then I can possibly run |
|
I think that you should make |
No description provided.