Hi @traai,
Your code has been quite useful and it has helped me to understand asynchronous methods much better.
I have a comment about the following line in the ActorLearner class:
self.barrier.wait()
If I understand correctly, this Barrier class is supposed to help us synchronize all the processes so that the initial parameters are initialized by the first process and then once again after all processes have finished synchronizing these values.
I have checked the Barrier class, however, and I think there are some issues with the wait() method.
def wait(self):
with self.counter.lock:
self.counter.val.value += 1
if self.counter.val.value == self.n:
self.barrier.release()
self.barrier.acquire()
self.barrier.release()
First, you use self.barrier.wait() twice, but the class counter value is never restarted, so that the condition if self.counter.val.value == self.n will never the satisfied again.
Second, the way the .release() methods are called results in the Semaphore value to become 1 after calling wait the first time. Because of this, the same logic can not be applied when calling wait() a second time...
I have created a notebook where you can check what I mean (although it is not very well organized).
I propose to change the wait() function to something like this:
def wait(self,name):
with self.counter.lock:
self.counter.val.value += 1
if self.counter.val.value % self.n == 0:
for i in range(self.n-1):
self.barrier.release()
return
self.barrier.acquire()
This way, we do not need to restart the counter value, and the last process to call the method will take care of releasing all the previous ones, leaving the Semaphore value at 0.
Hi @traai,
Your code has been quite useful and it has helped me to understand asynchronous methods much better.
I have a comment about the following line in the ActorLearner class:
self.barrier.wait()If I understand correctly, this Barrier class is supposed to help us synchronize all the processes so that the initial parameters are initialized by the first process and then once again after all processes have finished synchronizing these values.
I have checked the Barrier class, however, and I think there are some issues with the wait() method.
First, you use self.barrier.wait() twice, but the class counter value is never restarted, so that the condition
if self.counter.val.value == self.nwill never the satisfied again.Second, the way the
.release()methods are called results in the Semaphore value to become 1 after calling wait the first time. Because of this, the same logic can not be applied when callingwait()a second time...I have created a notebook where you can check what I mean (although it is not very well organized).
I propose to change the
wait()function to something like this:This way, we do not need to restart the counter value, and the last process to call the method will take care of releasing all the previous ones, leaving the Semaphore value at 0.