locking

Futex based locking mechanism

假装没事ソ 提交于 2019-12-04 17:41:07
Somebody can tell me an example of using locking mechanism based on futex? (for muticore x86 CPU, CentOS) Pthreads' mutexes are implemented using futexes on recent versions of Linux. Pthreads is the standard C threading API on Linux, and is part of the Posix standard, so you can easily port your program to other Unix-like systems. You should avoid using futexes directly unless you have very unusual needs, because they're very hard to use correctly - use pthreads, or a higher-level, language-specific API (which will almost certainly use pthreads itself). Have a look at https://github.com/avsm

Release a lock before waiting, and re-acquire it after

送分小仙女□ 提交于 2019-12-04 17:36:16
In Java, you can associate multiple Condition objects to a single ReentrantLock . What would the C# equivalent be? Real-world example: The example implementation in the Java Condition documentation uses two Condition objects, notFull and notEmpty , tied to the same lock. How could that example be translated to C#? Background : I often find Java code using two Condition objects to signal various states, associated to the same Lock ; in C#, it seems that you can either call Monitor.Enter on an object, and then Monitor.WaitOne / Monitor.Pulse , but that's just one condition. use multiple Auto

How to prevent overwriting an object someone else has modified

江枫思渺然 提交于 2019-12-04 17:29:07
I would like to find a generic way of preventing to save an object if it is saved after I checked it out. We can assume the object has a timestamp field that contains last modification time. If I had checked out (visited a view using a ModelForm for instance) at t1 and the object is saved again at t2 , given t2 > t1 I shouldn't be able to save it. Overwrite the save method that would first check the last timestamp: def save(self): if(self.id): foo = Foo.objects.get(pk=self.id) if(foo.timestamp > self.timestamp): raise Exception, "trying to save outdated Foo" super(Foo, self).save() 来源: https:/

Lock() in a static method

做~自己de王妃 提交于 2019-12-04 16:54:32
问题 I have a multi threaded application that writes to a settings xml file using a static method. I want to avoid that the file is being updated twice at the same time (causing accesss/write exception). How do I do that? This doesn't work: namespace Program { public class Settings { private static void SetSettingsValue (string settings, string value) { // make this thread safe to avoid writing to a locked settings xml file lock (typeof(Settings)) { //write data to xml file } } } } 回答1: The

How to implement locking in a multi process system?

折月煮酒 提交于 2019-12-04 16:51:34
We are running lots of jenkins projects in parallel. We are using python, and we have chosen to manage the virtual environments with pyenv. Unfortunately, pyenv has a well-known race condition . To work around the problem, I would like to implement locking at the process level. What I want to do is: lock some resource (a file?) do my pyenv stuff unlock the resource My scripts are written in bash. How can I implement resource locking / unlocking in bash? 2ps So your friend in the unix world when wanting a cross-process lock is a command called flock . It is implemented as an atomic operation at

Should a lock variable be declared volatile?

南笙酒味 提交于 2019-12-04 15:42:46
问题 I have the following Lock statement: private readonly object ownerLock_ = new object(); lock (ownerLock_) { } Should I use volatile keyword for my lock variable? private readonly volatile object ownerLock_ = new object(); On MSDN I saw that it usually used for a field that is accessed without locking, so if I use Lock I don't need to use volatile? From MSDN: The volatile modifier is usually used for a field that is accessed by multiple threads without using the lock statement to serialize

MySQL Error 1205: Lock wait timeout exceeded

ぃ、小莉子 提交于 2019-12-04 14:34:42
I'm using SQLyog to sync a production database to a dev db. On 4 tables, I'm getting: Error No. 1205 Lock wait timeout exceeded; try restarting transaction Researching the web seems to indicate that a transaction has begun, locked tables, but has not committed. One post said to SHOW PROCESSLIST; but the only processes appear to be my own, via SQLyog. I have also tried a Restart of MySQL, but that didn't help either. As a relative novice in MySQL, I'm stuck: I can't determine what transaction or process is locking the tables, nor how to clear this situation. Any suggestions would be gratefully

Fastest Multi-Reader / Single Writer Protection for Shared Resources - C++

岁酱吖の 提交于 2019-12-04 14:16:22
问题 I would like confirmation that my approach is extremely fast and appropriate for cross platform protection of a shared resource for a mostly multiple reader, single writer approach using C++. It favors writers such that when they enter all current threads are allowed to finish, but all new threads of any type must wait. The reverse of these two functions should be obvious. The reading I've done suggest that boost shared_mutex and other type rwlocks are not implemented very well and should be

C# - Locking issues with Mutex

孤街浪徒 提交于 2019-12-04 13:14:47
I've got a web application that controls which web applications get served traffic from our load balancer. The web application runs on each individual server. It keeps track of the "in or out" state for each application in an object in the ASP.NET application state, and the object is serialized to a file on the disk whenever the state is changed. The state is deserialized from the file when the web application starts. While the site itself only gets a couple requests a second tops, and the file it rarely accessed, I've found that it was extremely easy for some reason to get collisions while

Why await of Condition releases the lock but signal does not?

两盒软妹~` 提交于 2019-12-04 12:56:40
I write the below code to test when will the thread is awake when it is waiting for a Condition object. But I find I have to unlock after I call signal() . Lock is not release by this method, while await() will release this lock . This is from Condition#await The lock associated with this Condition is atomically released and the current thread becomes disabled for thread scheduling purposes and lies dormant until one of four things happens: And this is from Conditon#signal Wakes up one waiting thread. If any threads are waiting on this condition then one is selected for waking up. That thread