You can use a Channel instead of an Array to communicate. You can set the
channel's buffer size to 1, which ensures that only at most 1 message is in
the queue.

-erik

On Wed, Nov 18, 2015 at 5:01 AM, Yuhui ZHI <[email protected]> wrote:

>
>
> I have a list and two threads.
>
> One thread can push messages to the list and the other can pop messages
> from the list.
>
> So obviously I need to use something like "synchronized" in Java because I
> may push a very huge message into the list. If the push is not finished
> while the other thread wants to pop...
>
>
> If I'm right, "@async" can be used to create a thread. So here is what I
> do:
>
> arrTest = String[]
>
>
> @async begin
>    for i = 1 : 100
>       push!(arrTest, string(i))
>    end
> end
> @async begin
>    if length(arrTest) > 0
>       pop!(arrTest)
>    end
> end
>
>
>
>
>
> How to synchronize the push and the pop?
>



-- 
Erik Schnetter <[email protected]>
http://www.perimeterinstitute.ca/personal/eschnetter/

Reply via email to