Shop Learn P1 Docs P2 Docs Events
Taqoz Reloaded v2.8 - Exploring Locks — Parallax Forums

Taqoz Reloaded v2.8 - Exploring Locks

bob_g4bbybob_g4bby Posts: 354
edited 2022-06-27 11:01 in Forth

The P2 has 16 locks that are useful for protecting data or code from race conditions ( two or more cogs competing for the same resource leading to an indeterminate program state) Here's some code to explore the use of locks ( the assembler P2ASM needs to be loaded before loading the attached code ).

Running DEMO1 shows two cogs setting and releasing a lock each by running the .LOCKS debug word on a third cog.
Running DEMO2 shows two cogs acquiring and releasing one lock to prevent a race condition between them.
Both demos require an ANSI terminal like tera term for Windows and are stopped by pressing any key.

Sign In or Register to comment.