Hi,

I have a fairly typical 2-task write/read scenario, with one task writing 
into a fixed-length buffer, and the other task reading from it. I have the 
following piece of code in the write task:

function bufWrite(buf, value)
  if buf.full
    warn("Buffer is full")
    print("full = $(buf.full)\n")
    wait(buf.rdnotify)
  end
  :
  #do stuff to write value to the buffer
end

The read task is along the lines of:

function bufRead(buf)
  # do stuff to read a value from the buffer if non-empty
  buf.full = false
  notify(buf.rdnotify)
end

Given that @async tasks are not preemptive, I expected that between the 
buf.full flag check in the write task, and the print of the buf.full flag 
after the warn, the value of the full flag should not change because 
control does not pass to the read task until the wait() is encountered. 
However, I find that while the if buf.full check passes, the printed value 
of buf.full sometimes displays false - which means that the read task got 
control between the buf.full check and the print statement. Hence the 
question - can warn, print, etc. pass control to other tasks while 
executing?

Thanks,
Ravi

Reply via email to