How to use a castle in Julia

I work with Julia. IDE is Juno.

If I'm right, @async can generate a task, it's just like a thread.
Therefore, we can do this:

 @async begin # do something1 end @async begin # do something2 end 

Now I need to block the thread. For example, do something1 - click a message in the list, and do something2 - put a message from the same list.

This is similar to synchronized in Java.

what is synchronized in julia?

+4
source share
2 answers

There is also a @sync macro:

help? > @sync

Wait until all dynamically closed applications @async, @spawn, @spawnat and @parallel are full. All exceptions thrown by closed asynchronous 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 
+2
source

To save 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 
+2
source

All Articles