Questions tagged [spinlock]

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.

318 questions
1
vote
2 answers

Why are pthread spinlocks so much faster than mutexes?

I'm hacking on a fifo/queue for a multithreaded program using the following example as a guide. One thread writes to the fifo and another reads from it. The fifo will only be shared between these two threads. The synchronization overhead is massive;…
Björn Lindqvist
  • 19,221
  • 20
  • 87
  • 122
1
vote
0 answers

Why spin_lock_irqsave() is not used in wait_for_completion()?

I was going through with internals of "Completion" APIs, and found out that we cannot use wait_for_completion() if interrupts are already disabled on the processor. However semaphore does not have this restriction. Excerpt from kernel doc:…
1
vote
1 answer

Do pushcli() and popcli() in the spinlock of XV6 need atomic?

As learning XV6's spinlock,I thought a problem and don't find answer in google. In spinlock, pushcli() and popcli() used to insure interrupt handler run currently: void pushcli(void) { int eflags; eflags = readeflags(); cli(); if…
wcyiming
  • 23
  • 4
1
vote
1 answer

Why have AMD-CPUs such a silly PAUSE-timing

I've developed a monitor-object like that of Java for C++ with some improvements. The major improvement is that there's not only a spin-loop for locking and unlocking but also for waiting on an event. In this case you don't have to lock the mutex…
Bonita Montero
  • 2,817
  • 9
  • 22
1
vote
0 answers

What is the maximum amount of time CPU can be in critical section after acquiring spinlock?

What is the maximum amount of time CPU can be in critical section after acquiring Spin lock in Linux kernel?
Rahul Ravi
  • 819
  • 7
  • 5
1
vote
3 answers

Terminology question: mutex lock, spin lock, sleepable lock

All over StackOverflow and the net I see folks to distinguish mutexes and spinlocks as like mutex is a mutual exclusion lock providing acquire() and release() functions and if the lock is taken, then acquire() will allow a process to be…
1
vote
1 answer

mov vs xchg in spin lock implementatoin

I'm reading through this online book on x86 and I'm curious about an implementation detail in their example code for implementing a spin lock. In the example, they use a xchg to set a memory location to 0 rather than a mov and I'm trying to…
egerhard
  • 1,089
  • 1
  • 9
  • 18
1
vote
0 answers

kernel 4.4.192 spinlock already unlocked

during normal usage, the system locked up, and the following messages appeared on the screen. where you can see from the log, the spinlock owner and CPU are -1. After this BUG the system restarts by WatchDog. Our CPU is arm Cortex A9 iMX6DL, with…
Ivan Grimaldi
  • 11
  • 1
  • 3
1
vote
1 answer

How spin locks are implemented on platforms without CAS instructions?

The normal practice is to wrap the CAS instruction in a while loop on platforms that support CAS instructions. But platforms such as SPARC don't have atomic CAS instructions.
yeshengm
  • 557
  • 5
  • 13
1
vote
2 answers

Reason for using Volatile.Write at the beginning of a method

I think I slightly got the idea what exactly Volatile.Write and Volatile.Read do, but I've seen some examples where Volatile.Write is used at the beginning of a method like in the CLR via C# book where Jeffrey shows how to implement a Simple Spin…
E. Shcherbo
  • 1,128
  • 8
  • 15
1
vote
1 answer

Confusion around spin_lock_irqsave: in what nested situation is interrupt state kept?

There are many Q&As about spinlocks, but it's still confusing to me. I think it's because the questions and answers assume different settings or not clearly explain the settings about if it's SMP or if it's preemptive kernel or not when they ask or…
Chan Kim
  • 5,177
  • 12
  • 57
  • 112
1
vote
1 answer

Why do we need pushcli() before xchg()?

I was looking at this implementation of spinlocks, and in particular, the acquire and release functions: void acquire(struct spinlock *lk) { pushcli(); // disable interrupts to avoid deadlock. if(holding(lk)) panic("acquire"); // The xchg…
Abundance
  • 1,963
  • 3
  • 24
  • 46
1
vote
1 answer

Do spinlocks guarantee context switching when compared to mutexes

Consider the following code snippet int index = 0; av::utils::Lock lock(av::utils::Lock::EStrategy::eMutex); // Uses a mutex or a spin lock based on specified strategy. void fun() { for (int i = 0; i < 100; ++i) { lock.aquire(); …
Arun
  • 3,138
  • 4
  • 30
  • 41
1
vote
1 answer

How to get a global state of the locks in Linux kernel?

I'm writing some code for the Linux kernel and I noticed the interrupts are disabled when I need them to be enabled so that a process can handle a signal. It would be fantastic if I could just obtain a list of all the locks currently being hold in…
1
vote
0 answers

High-performance spinlock best practice

I'm writing a realtime audio multithreaded application, and during the render cycle sometimes there will be no jobs on the work queue. I would like the thread to wait for jobs without triggering an OS context switch (which could be too damaging to…
luqui
  • 59,485
  • 12
  • 145
  • 204