-
Notifications
You must be signed in to change notification settings - Fork 15
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
waiting on register modification events #156
base: master
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, seems like a good start! Let's discuss the points raised above.
src/semaphore.jl
Outdated
if s.nbwaiters[] > 0 | ||
unlock(s.lock) | ||
end | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The rest of the library does not automatically know about the existence of this file. In needs to be included from the main file src/QuantumSavory.jl
. Given that it is a dependency for the content of states_registers.jl
it should probably be included before it. E.g. here:
QuantumSavory.jl/src/QuantumSavory.jl
Line 82 in 46cb2f3
include("states_registers.jl") |
src/states_registers.jl
Outdated
"""Vector with a semaphore where processes can wait on until there's a change in the vector""" | ||
struct StateIndexVector | ||
data::Vector{Int} | ||
waiter::AsymmetricSemaphore | ||
end | ||
|
||
function StateIndexVector(data::Vector{Int}) | ||
env = ConcurrentSim.Simulation() | ||
return StateIndexVector(data, AsymmetricSemaphore(env)) | ||
end | ||
|
||
function getindex(vec::StateIndexVector, index::Int) | ||
return vec.data[index] | ||
end | ||
|
||
function setindex!(vec::StateIndexVector, value::Int, index::Int) | ||
vec.data[index] = value | ||
unlock(vec.waiter) | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is this for? Can it be removed?
src/states_registers.jl
Outdated
using ConcurrentSim | ||
using ResumableFunctions | ||
import Base: unlock, lock | ||
import Base: getindex, setindex! | ||
|
||
"""Multiple processes can wait on this semaphore for a permission to run given by another process""" | ||
struct AsymmetricSemaphore | ||
nbwaiters::Ref{Int} | ||
lock::Resource | ||
end | ||
AsymmetricSemaphore(sim) = AsymmetricSemaphore(Ref(0), Resource(sim,1,level=1)) # start locked | ||
|
||
function Base.lock(s::AsymmetricSemaphore) | ||
return @process _lock(s.lock.env, s) | ||
end | ||
|
||
@resumable function _lock(sim, s::AsymmetricSemaphore) | ||
s.nbwaiters[] += 1 | ||
@yield lock(s.lock) | ||
s.nbwaiters[] -= 1 | ||
if s.nbwaiters[] > 0 | ||
unlock(s.lock) | ||
end | ||
end | ||
|
||
function unlock(s::AsymmetricSemaphore) | ||
if s.nbwaiters[] > 0 | ||
unlock(s.lock) | ||
end | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems to be repeating the content of semaphore.jl
. I think my other comment about include
-ing semaphore.jl
will help clean this up.
src/ProtocolZoo/ProtocolZoo.jl
Outdated
@yield lock(prot.nodeA.stateindices.waiter) | ||
@yield lock(prot.nodeB.stateindices.waiter) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am not sure, but I think this should be @yield lock(...) | lock(...)
so that it runs whenever there is a change to either one of them. This would need more testing for correctness though.
…imulation object for all locks check for comments marked as "Step x" in swapping.jl and queries.jl
No description provided.