how to use lock in Julia

一曲冷凌霜 提交于 2019-12-05 12:34:47

There is also a @sync macro:

help?> @sync

Wait until all dynamically-enclosed uses of @async, @spawn, @spawnat and @parallel are complete. All exceptions thrown by enclosed async operations are collected and thrown as a CompositeException.

@sync @async begin
   # do something1
end

@sync begin
    # some code    
    @async begin
        # do something2
    end
    @async # do something 3
end

To keep a block mutex:

mutex = RemoteRef()

@async begin
   put!(mutex, true)
   # do something1
   take!(mutex)
end
@async begin
   put!(mutex, true)
   # do something2
   take!(mutex)
end
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!