You are here: About the Hardware > Locks

Locks

There are eight lock bits (also known as semaphores) available to facilitate exclusive access to user-defined resources among multiple cogs; the locks themselves are one of the mutually exclusive Shared Resources.  If a block of Main Memory is to be used by two or more cogs at once and that block consists of more than one long (four bytes), the cogs will each have to perform multiple reads and writes to retrieve or update that memory block.  This leads to the likely possibility of read/write contention on that memory block where one cog may be writing while another is reading, resulting in misreads and/or miswrites.

The locks are global bits accessed through the Hub via the hub instructions: LOCKNEW, LOCKRET, LOCKSET, and LOCKCLR.  Because locks are accessed only through the Hub, only one cog at a time can affect them, making this an effective control mechanism.  The Hub maintains an inventory of which locks are in use and their current states, and cogs can check out, return, set, and clear locks as needed during run time. 

Propeller Help Version 1.1

Copyright © Parallax Inc.

5/13/2009