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
2
votes
2 answers

Why is acquire semantics only for reads, not writes? How can an LL/SC acquire CAS take a lock without the store reordering with the critical section?

To start with, consider release semantics. If a data set is protected with a spinlock (mutex, etc. - no matters what exact implementation is used; for now, assume 0 means it's free and 1 - busy). After changing of the data set, a thread stores 0 to…
Netch
  • 4,171
  • 1
  • 19
  • 31
2
votes
1 answer

Is there a race condition in the linux ARM spinlock?

Here is the Linux implementation of a spinlock from arch/arm/include/asm/spinlock.h: static inline void arch_spin_lock(arch_spinlock_t *lock) { unsigned long tmp; u32 newval; arch_spinlock_t lockval; prefetchw(&lock->slock); …
awelkie
  • 2,422
  • 1
  • 22
  • 32
2
votes
0 answers

Why spinlock should be replaced by raw_spinlock in this Linux patch?

I am trying to understand this Linux commit (commit ID 830eec24673a982bff4df85ba4d17e4a6ff201a7). It converts a spinlock to raw_spinlock. But I am not clear about why spinlock will make a wake to a blocked idle task failed here. And why a…
Lesterth
  • 77
  • 1
  • 6
2
votes
1 answer

Spin wait C++11

I have the following struct struct info { unsigned long a; unsigned long b; }; atomic data; used by a writer thread and a reader thread. The reader has to respond to the new values as fast as possible. To do that I’ve implemented the…
toco
  • 29
  • 1
2
votes
1 answer

Does acquiring a spinlock require compare-and-swap or is swap enough?

Suppose we have a spinlock implementation: struct Lock { locked : Atomic(bool), } Then an unlock function could be: fun unlock(lock : &Lock) { atomic_store(&lock.locked, false, release); } But what about lock? Commonly, it uses a…
bzim
  • 1,002
  • 9
  • 17
2
votes
1 answer

What does it mean by code holding semaphore can be preempted

I was going through the Robert Love Book and was bit confused about this line. What does it mean by code holding semaphore can be preempted? If an interrupt occurs accessing the same variable which the user-space application has while it is…
2
votes
1 answer

Use of spinlock_check() function

I have a question about the function spinlock_check() used in spin_lock_init() macro. The code of spinlock_check is written below and it returns address of rlock static __always_inline raw_spinlock_t *spinlock_check(spinlock_t *lock) { return…
srikar sana
  • 115
  • 1
  • 9
2
votes
1 answer

Helgrind and atomic_flag

I tried the basic example of using atomic_flag at cplusplus.com. Valgrind's Helgrind tool reports 164 errors from 28 contexts (suppressed: 0 from 0) with examples such as ==4868== Possible data race during read of size 1 at 0x605220 by thread…
John Perry
  • 2,497
  • 2
  • 19
  • 28
2
votes
3 answers

When is a good idea to use a spinlock?

It seems that spinlocks aren't that great as they waste CPU cycles when the are waiting (blocking). If the thread just goes to sleep while waiting for a signal to wakeup, then CPU cycles aren't lost while spinning. Maybe it is good to use a spinlock…
Bobby S
  • 4,006
  • 9
  • 42
  • 61
2
votes
0 answers

How to properly implement a cross-platform spinlock in c++

Essentially, my question is: What does an "good" implementation of a spinlock look like in c++ which works on the "usual" CPU/OS/Compiler combinations (x86 & arm, Windows & Linux, msvc & clang & g++ (maybe also icc) ). Explanation: As I wrote in…
MikeMB
  • 20,029
  • 9
  • 57
  • 102
2
votes
2 answers

How to find out which kernel spinlock eat up most of CPU?

I'm doing performance tuning of a crypto software, which is run on Linux and utilizes hardware crypto acceleration device. When the load is given over some threshold, kernel _spn_lock begin to eat most of the CPU's time. The following perf top…
Chul-Woong Yang
  • 1,223
  • 10
  • 17
2
votes
1 answer

Spinlock in device driver

Can anybody explain exact use of spinlock in case of device driver. I am just confused as in many of the interrupt handler routines i have seen spinlocks. As spinlock are busy waiting. it can make delay in other interrupts.. Please if possible list…
manish
  • 21
  • 2
2
votes
2 answers

How to use spinlock in linux?

I am a computer science student, I have one assignment asking me to use spinlock to lock a thread and unlock it once its critical section is completed. The difficulty is I googled many times, but I did not find any useful information. For example, I…
ikd29123
  • 21
  • 1
  • 3
2
votes
0 answers

Identify spinlock holder

Is it possible to find out who (place in code) locked a spinlock? Some file with statistics or so? More info about my issue: I have a place in code which is trying to obtain a spinlock. The cpu core which runs the kernel thread with…
René Kolařík
  • 1,244
  • 1
  • 10
  • 18
2
votes
2 answers

Can atomic ops based spin lock's Unlock directly set the lock flag to zero?

Say for example, I have an exclusive atomic-ops-based spin lock implementation as below: bool TryLock(volatile TInt32 * pFlag) { return !(AtomicOps::Exchange32(pFlag, 1) == 1); } void Lock (volatile TInt32 * pFlag) { while…
Abhishek Jain
  • 9,614
  • 5
  • 26
  • 40