The invention provides a
spin lock implementation method and device based on hardware
semaphore, equipment and a medium, and relates to the field of embedded operating systems, the method comprises the following steps: binding a
spin lock with the hardware
semaphore, and allocating a counting register to the
spin lock; if the first core requests to acquire the spin lock, verifying whether the current holder of the hardware
semaphore is the first core; if yes, reading a count value for validity check, and if valid, adding 1 to the count value and returning; if the core is not the first core, hardware semaphore locking is called; after the hardware semaphore is obtained, whether a current holder is a first core is verified, if yes, whether a count value is 0 is verified, and if yes, 1 is added to the count value, and a
memory barrier instruction is inserted; if the first core requests to release the spin lock, verifying whether the first core is a holder of the spin lock; if yes, subtracting 1 from the count value, judging whether the count value is 0 or not, and if yes, calling hardware semaphore for unlocking to complete lock release. The scheme can reduce
system power consumption.