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
1 answer

Usage of spinlock and cli together

I recently downloaded linux source from http://www.kernel.org/pub/linux/kernel/v2.6/linux-2.6.34.1.tar.bz2 . I came across the below paragraph in the file called spinlocks.txt in linux-2.6.34.1\Documentation folder. " it does mean that if you have…
Karthik Balaguru
  • 7,424
  • 7
  • 48
  • 65
2
votes
0 answers

spin_lock before writing status register

I'm looking at linux driver where I see this: spin_lock_bh(&driver->xy_lock); /* code to clear a status bit from 32 bit PCI register */ iowrite32(...); spin_unlock_bh(&driver->xy_lock); Isn't this unnecessary to obtain a lock to clear a status…
Matt J.
  • 21
  • 1
2
votes
3 answers

Can I use LDREX/STREX to implement a spin lock without enabling SCU in a multicore ARM Cortex-A9 SoC?

I know this might be a strange usage. I just want to know if I can use LDREX/STREX with SCU disabled. I am using a dual-core Cortext-A9 SoC. The two cores are running in an AMP mode: each core has its own OS. Although memory controller is shared…
yelInv
  • 23
  • 6
2
votes
1 answer

spin lock vs mutex sleep lock

Spin locks (busy waiting locks) are more efficient than mutex sleep locks for very short critical sections. Suppose that the context switch time for a system (the time it takes to save the current process and load the next) is time T. How long can a…
sunil kalluri
  • 21
  • 1
  • 3
2
votes
1 answer

c++: spin lock or mutex comparison (simple calculations)

Spin lock should have better performance than mutex for simple tasks. However, in this simple test (8 threads incrementing a counter), the results shows differently: #include #include #include #include #include…
user2847598
  • 1,247
  • 1
  • 14
  • 25
2
votes
2 answers

Cross-platform and cross-process atomic int writes on file

I'm writing an application that will have to be able to handle many concurrent accesses to it, either by threads as by processes. So no mutex'es or locks should be applied to this. To make the use of locks go down to a minimum, I'm designing for the…
Waneck
  • 2,450
  • 1
  • 19
  • 31
2
votes
1 answer

why spin_lock_irqsave needs to disable preemption on multiprocessor

Just curious why spin_lock_irqsave needs to disable the preemption after disabling local interrupt. static inline unsigned long __raw_spin_lock_irqsave(raw_spinlock_t *lock) { unsigned long flags; local_irq_save(flags); …
eric chen
  • 21
  • 3
2
votes
2 answers

Is it safe to spin on a volatile variable in user-mode threads?

I'm not quite sure if it's safe to spin on a volatile variable in user-mode threads, to implement a light-weight spin_lock, I looked at the tbb source code, tbb_machine.h:170, //! Spin WHILE the value of the variable is equal to a given value /** T…
yongsun
  • 105
  • 7
2
votes
4 answers

How to implement a spinlock to avoid blocking

Consider the following code: // Below block executed by thread t1 synchronized(obj) { obj.wait(0); } // This block executed by thread t2 synchronized(obj) { obj.notify(); } I understand that in above code if t1 has taken ownership of…
2
votes
4 answers

for with one parameter

Reading that spinlock and other multitasking stuff, I faced to this code: #include #include #include #include #include class SpinLock { boost::atomic_flag…
Qeeet
  • 303
  • 3
  • 13
2
votes
1 answer

What guarantee thread with spin lock on multiprocessor run on a different processor

I know spin lock only works on multiprocessor. But if two threads try to acquire the same resource and one is put on spinlock, what prevents the other one not running on the same processor? If it happens the one with spin lock will prevent the one…
2
votes
3 answers

Why does one loop take longer to detect a shared memory update than another loop?

I've written a 'server' program that writes to shared memory, and a client program that reads from the memory. The server has different 'channels' that it can be writing to, which are just different linked lists that it's appending items too. The…
Joseph Garvin
  • 20,727
  • 18
  • 94
  • 165
2
votes
1 answer

spinlock shared between process and interrupt context

If a spinlock is held in the process context. What will happen if the same spinlock is required in an interrupt context? Either the interrupt handler wait until the spinlock is released by the process, or the interrupt handler will schedule it on…
one.prav
  • 51
  • 5
2
votes
3 answers

What is the minimum X86 assembly needed for a spinlock

To implement a spinlock in assembly. Here I post a solution I came up with. Is it correct? Do you know a shorter one? lock: mov ecx, 0 .loop: xchg [eax], ecx cmp ecx, 0 je .loop release: lock dec dword [eax] eax is initialized…
melkyades
  • 1,719
  • 11
  • 20
2
votes
0 answers

spin_lock_irqsave and alloc inside rcu_read_lock

Hi, I have a driver code which is supposed to work on certain packets received on the interface.The driver uses spin_lock_irqsave to manage parallel such requests before giving it to the hardware. To work on the packet, it requires some context…
CodeQ
  • 319
  • 1
  • 3
  • 13