!🔒Block Lock Demo🔓

by Michael Piz

Version 1 (February 26, 2021)

Download (5 downloads)

(It's not as complicated as it looks in the preview. 😎)

This demo shows how to lock any block sequence so that only one fiber at a time can execute it.

To run the demo, just tap "Start." (I recommend clearing the log first.) The demo runs five fibers that start at random intervals, each one executing the same "Flow beginning" block.. That sequence locks a 'Delay 5s' block so that only one fiber can execute it at a time. (For production, you would replace that block with the actual sequence you want to lock.)

Output messages are logged so you can see that no fiber can execute the locked block while any other fiber has control of it. (The messages are also toasted, though I find the toast more fun than helpful.) The log is where the relevant info can be found and followed to see what's going on. In the log, flow output lines are prefixed with "*****" so they're easier to find.

When you view the flow, you'll see three "Flow Beginning" blocks. One fires up the five fibers, which each then start the second one. The second one isn't meant to be run directly, it just executes the lock mechanism (and a ton of demo-related stuff that makes tracing the actual lock mechanism a real adventure). The third one isn't meant to be executed - it's merely the lock mechanism stripped of all the demo stuff so it's much easier to follow.

In that second flow, there are labels all around that try to explain what's demo stuff and what's lock mechanism. You're better off just looking at the third flow.

This is my first demo, so if you find flaws with it please let me know so I can fix them. In particular, I'd like to know for certain if this mechanism prevents race conditions.

Thanks for checking out my demo!