Open appascoe opened 6 years ago
Yes, that example would be better written as
server = listen(2000)
while true
let sock = accept(server)
@async begin
x = readline(sock)
write(sock, x)
end
end
end
The practice of enforcing closures should probably also be a section in the Parallel Computing chapter as well.
Discourse thread for reference: https://discourse.julialang.org/t/inconsistent-results-based-on-number-of-processes/5191
At the very least, there's a documentation issue. The example of a network server that can service multiple connections has a critical flaw because, we believe, the changes in closures from 0.4 to 0.5:
Because a second connection was opened before there was a write to the first connection,
sock
got overwritten, causing the write on the first connection to be echoed on the second. This makes asynchronous and parallel tasks more difficult to reason about, and it's not obvious that this is expected/desired behavior.