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

Inconsistent timings when passing data between two threads

I have a piece of code that I use to test various containers (e.g. deque and a circular buffer) when passing data from a producer (thread 1) to a consumer (thread 2). A data is represented by a struct with a pair of timestamps. First timestamp is…
Cattus
  • 147
  • 6
0
votes
1 answer

How to solve the spinlock lockup in SMP,both the irq and function want the lock?

Our system(linux) have a spin_lock lockup/deadlock problem, but I don't have a good idea to solve it. The spinlock can be get in irq and a data transmit function. The lockup happened when: The app is going to transmit data, then it acquired the…
TonyHo
  • 244
  • 5
  • 9
0
votes
1 answer

Hybrid mutex library for Linux

Is there any standard threading library for Linux which implements hybrid mutex capabilities? I mean, a mutex which, at first, "behaves like a spinlock" and "only if the lock has still not been obtained after a certain amount of time (or retries or…
LuisABOL
  • 2,951
  • 4
  • 25
  • 57
0
votes
1 answer

Debugging simplified version of Lamport's Bakery Algorithm in C

I'm trying to implement a simplified version of Lamport's Bakery Algorithm in C before I attempt to use it to solve a more complex problem.* The simplification I am making is that the lock is only shared by only two threads instead of N. I set up…
Glenn
  • 386
  • 3
  • 12
0
votes
1 answer

SpinLock in C#. In which type of algorithm SpinLock is a better choice against Monitor?

Possible Duplicate: Why everyone states that SpinLock is faster? This question is concerning SpinLock, Monitor & Interlocked. I made 2 tests which test the performance of Monitor, SpinLock and Interlocked and these tests have left me confused. My…
Rauf
  • 312
  • 3
  • 16
0
votes
1 answer

Seconds overflow in pthread_cond_timedwait

I have a usecase in which I want to acquire a condition variable and release it after some time interval( Eg: I have a queue of time ordered events and I want to block for a specified duration .) Duration = Earliest Time in Q - Current Time() I…
KodeWarrior
  • 3,538
  • 3
  • 26
  • 40
0
votes
1 answer

Is it safe to call a non-void function inside kernel without assigning to variable

I am trying to debug a kernel code, because of a "scheduling while in atomic" that is crashing my system. In some point of an actual kernel module I added a line for calling a function defined in another kernel module (this one made by me). The call…
jeanc
  • 4,563
  • 4
  • 22
  • 27
0
votes
1 answer

Shared Counter Gives Different Value With Spinlocks

I have the following code: #include #include #define THREAD_CNT 10 #define ITER 100 #define PRINT 1 int lock; unsigned long long int counter; void spin_lock(int *p) { while(!__sync_bool_compare_and_swap(p, 0, 1)); } void…
aqua
  • 3,269
  • 28
  • 41
0
votes
1 answer

Disabling the scheduler to reduce the cpu time on spinlock

In linux, in kvm environment, when a process in VM locks on some resource and is pre-empted, other processes of VM, which need that locked resource would spend time on spinlock. And the process would unlock the resource when it's allotted the…
rAzOr
  • 300
  • 6
  • 19
-1
votes
2 answers

Multithreading error: Why is there more than one thread in a loop where I expected only one at a time?

Offending code: object _objLock = new object(); bool _isCurrentlyUpdatingValues = false; public void UpdateTestReadValuesTimerCallback(object state) { try { lock (_objLock) { if (_isCurrentlyUpdatingValues ==…
Eric Ouellet
  • 10,996
  • 11
  • 84
  • 119
-1
votes
1 answer

What kind of functions cannot be used in the critical section of the spin lock?

I'm kind of confused about what sort of functions are not allowed in a spin lock's critical section. In particular I'm confused about reentrant functions. I thought that all reentrant functions are unsafe to use in a spin lock's critical section,…
Shisui
  • 1,051
  • 1
  • 8
  • 23
-1
votes
1 answer

Do the glibc implementation of pthread_spin_lock() and pthread_spin_unlock() function have memory fence instructions?

Do the glibc implementation of pthread_spin_lock() and pthread_spin_unlock() function have memory fence instructions? (I could not find any fence instructions.) Similar question has answers here. Does pthread_mutex_lock contains memory fence…
Hiro Yoshioka
  • 29
  • 1
  • 5
-1
votes
1 answer

What exact "resources" are released, when calling pthread_spin_destroy()?

I have a question regarding the phread_spin_destroy() function. In the posix standard it is defined as follows: The pthread_spin_destroy() function shall destroy the spin lock referenced by lock and release any resources used by the lock. So if…
lospollos
  • 45
  • 5
-1
votes
1 answer

which processor will acquire the spinlock?

In a 4 processor system, which of the three processor (all the 3 processors are spinning to acquire the spin lock) will acquire the spinlock released by the fourth processor?
Madara
  • 163
  • 2
  • 11
-1
votes
1 answer

Pre-emption can occur if the code exceeds the time slice intended for it, then how do we ensure code length/execution time in the spinlock?

--> Re-editing my question. I thought to picture my understanding. Here is the picture. Please correct me here. By task, I mean process only. A picture is worth a thousand words. What will happen in the multi-processor, if the third process wants…
dexterous
  • 6,422
  • 12
  • 51
  • 99
1 2 3
21
22