Are there any synchronization primitives in snap like mutex, semaphore

I want to implement producer-consumer problem. Are there any synchronization primitives in snap like mutex, semaphore ... that can be used for synchronizing in a single sprite ?

I don't think so

When I've needed to sync things I've just local or global variables (depending on whether I'm syncronising within a sprite or between several sprites) together with the ubiquitous wait until block or repeat until loop

And broadcast/broadcast and wait are are also very useful in this respect

Hi! Snap! doesn't have truly asynchronous threads; scheduling happens only when a thread deliberately yields, which it does at the bottom of the looping primitives and at explicit WAIT blocks. (There are a few other cases, the primitives that are expected to be time-consuming, such as GLIDE.) In particular, a thread is never interrupted between the computation of the test part of an IF and the computation of the chosen action. This pretty much eliminates the need for mutexes. If you want to teach about synchronization you'll have to simulate asynchronous events by saying, for example,
untitled script pic

(The above isn't actually quite true. If a thread runs for a really long time, the Snap! scheduler will force-yield it, so that you can recover from infinite loops in your code.)

Snap doesnt have this, but, you can use the [scratchblocks] inherit [ v] :: variables [/scratchblocks] block so other sprites inherit this sprite's x, y, z, direction, hidden or not, etc.

What does that have to do with the question?

Now that I think about it, I guess it doesnt

Also the inherit block doesnt work anymore

please start a new thread with an example

ok i will

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.