locking

Playframework concurrent jobs management

天涯浪子 提交于 2019-12-12 18:28:00
问题 I would like to have some advise on multiple concurrent job management in play : in fact, i'm using in my application two distincts jobs : the first job is a quick one : it tries to reach two distinct url using WS.url() method and record the resulting status into database. Three retry are done if a website does not responding. This task takes less than 20s to finish, and is going to be run every 5 minutes. the second job is a slow one : it parses content into both websites if their status

Ruby - Redis based mutex with expiration implementation

情到浓时终转凉″ 提交于 2019-12-12 17:11:25
问题 I'm trying to implement a memory based, multi process shared mutex, which supports timeout, using Redis. I need the mutex to be non-blocking, meaning that I just need to be able to know if I was able to fetch the mutex or not, and if not - simply continue with execution of fallback code. something along these lines: if lock('my_lock_key', timeout: 1.minute) # Do some job else # exit end An un-expiring mutex could be implemented using redis's setnx mutex 1 : if redis.setnx('#{mutex}', '1') #

.Net4, Monitor.Enter(lockObject, acquiredLock)

喜你入骨 提交于 2019-12-12 16:25:29
问题 In .Net4, Monitor.Enter(Object) is marked as obsolete : [ObsoleteAttribute("This method does not allow its caller to reliably release the lock. Please use an overload with a lockTaken argument instead.")] public static void Enter( Object obj ) And there is a new method Monitor.Enter(lockObject, acquiredLock) with this usage : bool acquiredLock = false; try { Monitor.Enter(lockObject, ref acquiredLock); // Code that accesses resources that are protected by the lock. } finally { if

Reliability of file locking on network files

佐手、 提交于 2019-12-12 14:53:26
问题 I read that file locking on network files isn't very reliable. I'm using those LockFile/LockFileEx/UnlockFile win32-api functions for range-locks. Does anyone have some experience of using those functions on files living on a network-share? 回答1: Win32 file locking mechanisms are reliable IF they're done to a remote CIFS share. There have been many flat file databases that work just quite reliably using these mechanisms for decades. They're not reliable if they're done on a remote NFS share

Object intrinsic monitor as java.util.concurrent.Lock

半城伤御伤魂 提交于 2019-12-12 14:33:37
问题 I believe it could be very useful to be able to use an object's monitor as a Lock . That is : synchronized(object) { ... } would be equivalent to : lock.lock(); try { ... } finally { lock.unlock(); } As far as i understand it, it is not possible to achieve this using Lock interface since synchronization only happens in blocks. A solution i see would be to have java.lang.Object be enriched with an extra method public Lock asLock/getIntrinsicMonitorObject(); // Name isn't perfect but i'm not

Should I protect operations on primitive types with mutexes for being thread-safe in C++?

风流意气都作罢 提交于 2019-12-12 14:23:23
问题 What is the best approach to achieve thread-safety for rather simple operations? Consider a pair of functions: void setVal(int val) { this->_val = val; } int getVal() { return this->_val; } Since even assignments of primitive types aren't guaranteed to be atomic, should I modify every getter and setter in the program in the following way to be thread-safe? void setVal(int val) { this->_mutex.lock(); this->_val = val; this->_mutex.unlock(); } int getVal() { this->_mutex.lock(); int result =

How to I force lock escalation (to flush out deadlock issues) during testing?

只愿长相守 提交于 2019-12-12 14:21:24
问题 Posting the question and one answer here. Maybe somebody has better answer... It's possible to write code that triggers a deadlock even for a single user if the developer accidentally opens up a second connection to the database instead of reusing the an existing one (which might already have an open transaction). Certain O/RM and LINQ frameworks make this mistake easy. Here is the scenario in pure SQL terms: --Setup: CREATE TABLE Vendors(VendorID int NOT NULL, VendorName nvarchar(100) NOT

Mutex release issues in ASP.NET C# code

邮差的信 提交于 2019-12-12 13:44:24
问题 I'm not exactly sure how to address this issue. I have a mutex that is declared as such: public class MyNamedLock { private Mutex mtx; private string _strLkName; public MyNamedLock(string strLockName) { _strLkName = strLockName; //... mtx = new Mutex(false, _strLkName, out bCreatedNew, mSec); } public bool enterLockWithTimeout(int nmsWait = 30 * 1000) { _nmsWaitLock = nmsWait; //Wait return mtx.WaitOne(nmsWait); } public void leaveLock() { _nmsWaitLock = 0; //Release it mtx.ReleaseMutex(); }

Producer Consumer scenario with Reentrant Lock and Condition in Java

荒凉一梦 提交于 2019-12-12 13:16:07
问题 I have written a Producer Consumer program using Reentrant Lock and condition. It is working correctly, but I am not very sure whether implementation is correct. Moreover it does not seem to be optimal. Can somebody please verify if this is a correct implementation, moreover can you please tell, how to optimize it, like - taking lock at the place where it is really required public class TestRL { static class Observed { boolean filled = false; public void setFilled(boolean filled) { this

Monitor.TryEnter / Monitor.Exit and SynchronizationLockException

社会主义新天地 提交于 2019-12-12 12:17:37
问题 Is it possible to detect if the same thread trying to release the lock? We have many places in code that looks like: try { try { if(!Monitor.TryEnter(obj, 2000)) { throw new Exception("can not lock"); } } finally { Monitor.Exit(obj); } } catch { //Log } The above code very simplified, and actually Enter and Exit statement located in custom object (lock manager). The problem, that in that structure, we have SynchronizationLockException when trying to "Exit", since it looks like the thread that