spinlock

How to migrate from OSSpinLock to os_unfair_lock()?

不想你离开。 提交于 2020-05-29 11:22:53
问题 As of macOS 10.12, OSSpinLock has been deprecated. The XCode error messages urge me to use os_unfair_lock_unlock() instead. As a legacy of some open source stuff I'm relying on, I'm using RegexKitLite from 2010. How can I convert the spin lock type? Simple unlocking and locking I can manage, but these comparisons are giving me headache: if(rkl_cacheSpinLock != (OSSpinLock)0) { ... } rkl_cacheSpinLock is of type os_unfair_lock and has been initialized. OSSpinLock seems to be of type int , so

How to migrate from OSSpinLock to os_unfair_lock()?

安稳与你 提交于 2020-05-29 11:21:27
问题 As of macOS 10.12, OSSpinLock has been deprecated. The XCode error messages urge me to use os_unfair_lock_unlock() instead. As a legacy of some open source stuff I'm relying on, I'm using RegexKitLite from 2010. How can I convert the spin lock type? Simple unlocking and locking I can manage, but these comparisons are giving me headache: if(rkl_cacheSpinLock != (OSSpinLock)0) { ... } rkl_cacheSpinLock is of type os_unfair_lock and has been initialized. OSSpinLock seems to be of type int , so

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?

只愿长相守 提交于 2020-01-22 16:36:06
问题 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 spinlock address. To force visibility of all previous actions before storing 0 to spinlock address, storing is executed with release semantics, that means all previous reads and writes shall be made visible to other threads before this storing. It

GLSL per-pixel spinlock using imageAtomicCompSwap

£可爱£侵袭症+ 提交于 2020-01-16 16:01:33
问题 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 corresponding to the same pixel coordinate. layout (binding = 0, r32ui) uniform volatile coherent uimage2D lock_image; void main(void) { ivec2 pos = ivec2(gl_FragCoord.xy); // spinlock - acquire uint lock_available; do { lock_available =

When should & shouldn't I use this C# utility class to control threads via Interlocked

妖精的绣舞 提交于 2020-01-13 16:29:10
问题 I'm trying to understand the logic behind how this class was written, and when I should and shouldn't use it. Any insight would be appreciated internal struct SpinLock { private volatile int lockHeld; private readonly static int processorCount; public bool IsHeld { get { return this.lockHeld != 0; } } static SpinLock() { SpinLock.processorCount = Environment.ProcessorCount; } public void Enter() { if (Interlocked.CompareExchange(ref this.lockHeld, 1, 0) != 0) { this.EnterSpin(); } } private

Non-blocking socket accept without spinlock in C [duplicate]

删除回忆录丶 提交于 2020-01-05 03:32:13
问题 This question already has answers here : Closed 7 years ago . Possible Duplicate: Wake up thread blocked on accept() call I am writing a small server which listening for connections (accepting them and passing them to worker threads) until a custom stop signal is sent. If I use blocking sockets, then my main accept loop cannot break on the custom stop signal being sent. However, I wish to avoid having a busy-wait/spinlock loop with a non-blocking socket. What I want is for my main accept loop

Non-blocking socket accept without spinlock in C [duplicate]

旧巷老猫 提交于 2020-01-05 03:31:14
问题 This question already has answers here : Closed 7 years ago . Possible Duplicate: Wake up thread blocked on accept() call I am writing a small server which listening for connections (accepting them and passing them to worker threads) until a custom stop signal is sent. If I use blocking sockets, then my main accept loop cannot break on the custom stop signal being sent. However, I wish to avoid having a busy-wait/spinlock loop with a non-blocking socket. What I want is for my main accept loop

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

拈花ヽ惹草 提交于 2020-01-05 02:48:13
问题 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 (AtomicOps::Exchange32(pFlag, 1) == 1) { AtomicOps::ThreadYield(); } } void Unlock (volatile TInt32 * pFlag) { *pFlag = 0; // is this ok? or here as well a atomicity is needed for load and store } Where AtomicOps::Exchange32 is implemented on windows using

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

故事扮演 提交于 2020-01-05 02:48:05
问题 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 (AtomicOps::Exchange32(pFlag, 1) == 1) { AtomicOps::ThreadYield(); } } void Unlock (volatile TInt32 * pFlag) { *pFlag = 0; // is this ok? or here as well a atomicity is needed for load and store } Where AtomicOps::Exchange32 is implemented on windows using

spin_lock on non-preemtive linux kernels

孤人 提交于 2019-12-30 10:10:22
问题 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 non-preemtive kernels interrupt handlers may still be executed for example or I might call a function that would put the original thread to sleep. So it's not true that an empty spin_lock call is "safe" as it would be if it was implemented as a mutex. Is there