Atomic block in @async


I am using my own version of pmap as described here:

Is there a way to run some block atomically?
I have an array where I push data to and delete data.
At the moment I am using findmax() and after that deleteat where the index depends on findmax is there a way to run these atomically?
Looks like sometimes a push changes the index and then the wrong element gets deleted.


I can’t comment on your particular application because you haven’t given enough information.

But note this from the section of the documentation that you referenced:

If your findmax and subsequent deleteat is in the @async block on the local process, then it should be atomic since task switching is cooperative.

On the other hand, it might not be atomic if for example your findmax and deleteat are separated by a blocking operation (e.g. remotecall_fetch), or if findmax is calculated and returned remotely on a SharedArray.


I’m still trying to figure out where exactly the issue is. Everything I’m interested in atm is the master processor. That one works on normal arrays. I’ll add a comment when I figure out what exactly is wrong if it has something to do with this. Thanks :wink: