A spinlock is a lock which causes a thread trying to acquire it to simply wait in a loop ("spin") while repeatedly checking if the lock is available.
Questions tagged [spinlock]
318 questions
6
votes
2 answers
Use of STREXEQ instead of STREX for spinlock implementation in ARM
The following is a sample spin-lock implementation in the ARM manual. Please check here: http://infocenter.arm.com/help/topic/com.arm.doc.genc007826/Barrier_Litmus_Tests_and_Cookbook_A08.pdf . Section on "Use of Wait For Event (WFE) and Send Event…

piscianemperor
- 99
- 2
- 9
5
votes
1 answer
Which spinlock method is more efficient: retry test_and_set(), or spin read-only on test()?
Which spinlock method is better (in terms of efficiency)?
#include
#define METHOD 1
int main( )
{
std::atomic_flag lock { };
#if METHOD == 1
while ( lock.test_and_set( std::memory_order_acquire ) )
{
while (…

digito_evo
- 3,216
- 2
- 14
- 42
5
votes
2 answers
'OSSpinLock' was deprecated in iOS 10.0: Use os_unfair_lock() from instead
I went through this Question but the provided solution didn't work. Can someone please explain any alternative approach or proper implementation using os_unfair_lock()?
when I am using 'OS_UNFAIR_LOCK_INIT', it seems unavailable.
Thanks!

Renuka Pandey
- 1,730
- 2
- 15
- 27
5
votes
3 answers
Why the perf always show _raw_spin_unlock_irqrestore or some other spin unlock function
Does anyone know Why the perf always show _raw_spin_unlock_irqrestore or some other spin unlock function? The spin_unlock implementation is usually simpler compared with spin_lock. If there is high contending on the spin_lock, does not the perf…

JC.wang
- 101
- 1
- 5
5
votes
2 answers
Are the memory barriers correct for this lock?
Is this correct? And am I correct in assuming that applying the memory ordering on the std::atomic_flag does NOT provide synchronization for general-purpose locks?
#include
class Spinlock
{
public:
Spinlock(): f(ATOMIC_FLAG_INIT) {}
…

chbaker0
- 1,758
- 2
- 13
- 27
4
votes
2 answers
Fair Reader-Writer Ticket Spinlock in C++ running slow
I have recently implemented a fair reader-writer ticket-spinlock in C++. The code is fairly simple and I thought it was working great. I have integrated the spinlock into a larger application and I noticed that on some rare occasions, the code is…

Guillaume Holley
- 71
- 4
4
votes
3 answers
GLSL per-pixel spinlock using imageAtomicCompSwap
OpenGL red book version 9 (OpenGL 4.5) example 11.13 is Simple Per-Pixel Mutex. It uses imageAtomicCompSwap in a do {} while() loop to take a per-pixel lock to prevent simultaneous access to a shared resouce between pixel shader invocations…

Zhibo Shen
- 135
- 8
4
votes
1 answer
Kernel block device - Falling in deadlock using spinlock
I just implemented a virtual block device and I would like to play with it in order to explore how linux kernel handles block devices.
My device is just a memory zone divided in two 512 bytes sectors.
I'm using a global structure to store device…

Arkaik
- 852
- 2
- 19
- 39
4
votes
0 answers
Windows Filtering Platform Network Slowdown Due to Spinlock
I am writing a Windows Filtering Platform Kernel Mode Driver, the goal of the driver is to capture all traffic on a particular layer, and communicate this traffic back down to user-mode so that it can be further analyses. The driver never needs to…

Dan
- 3,879
- 5
- 36
- 50
4
votes
0 answers
Using Swoole locks in PHP
I'm working on a new project which should be implemented by Swoole extension.
Here is the docs for swoole locks:
https://www.swoole.co.uk/docs/modules/swoole-lock
Here is supported lock types:
SWOOLE_FILELOCK: file lock
SWOOLE_RWLOCK: read write…

Davis.S
- 41
- 3
4
votes
2 answers
Disabling all interrupts to protect CPU register state on multi processor systems
I need to ensure in a code portion (in kernel mode) that no one else can modify/check the CR0 register. On a one-processor system I think disabling interrupts is the best. But on multi-processor systems :
Is there a way to disable ALL interrupts…

jérôme
- 41
- 1
- 2
4
votes
2 answers
Why CLH Lock need prev-Node in java
This is a typical CLH-Lock in java:
public class CLHLock{
private final AtomicReference tail;
// why we need this node?
private final ThreadLocal myPred;
private final ThreadLocal myNode;
public CLHLock() {
…
user5134456
4
votes
1 answer
Locks around memory manipulation via inline assembly
I am new to the low level stuff so I am completely oblivious of what kind of problems you might face down there and I am not even sure if I understand the term "atomic" right. Right now I am trying to make simple atomic locks around memory…

user1235831
- 111
- 1
- 8
4
votes
4 answers
spin_lock on non-preemtive linux kernels
I read that on a system with 1 CPU and non preemtive linux kernel (2.6.x) a spin_lock call is equivalent to an empty call, and thus implemented that way.
I can't understand that: shouldn't it be equivalent to a sleep on a mutex? Even on…

Emiliano
- 22,232
- 11
- 45
- 59
4
votes
1 answer
What does raw_spinlock mean?
I was studying the raw_spinlock struct, which is in /usr/src/linux/include/linux/spinlock_types.h:
typedef struct raw_spinlock {
arch_spinlock_t raw_lock;
#ifdef CONFIG_GENERIC_LOCKBREAK
unsigned int break_lock;
#endif
#ifdef…

JuHyung Son
- 73
- 2
- 8