locking

How does this canonical flock example work?

牧云@^-^@ 提交于 2019-12-01 08:22:53
When one must synchronize programs (shell scripts) via file system, I have found an flock -based solution to be recommended (should also work on NFS ). The canonical example for usage from within a script (from http://linux.die.net/man/1/flock ) is: ( flock -s 200 # ... commands executed under lock ... ) 200>/var/lock/mylockfile I don't quite get why this whole construct ensures atomicity. In particular, I am wondering in which order flock -s 200 and 200>/var/lock/mylockfile are executed when e.g. bash executes these lines of code. Is this order guaranteed/deterministic? The way I understand

Is using an existing object rather than creating a specific lock object safe?

时光怂恿深爱的人放手 提交于 2019-12-01 07:45:40
问题 EDIT: As it turns out when I was browsing I found a question the appears to be the same as mine which I didn't find earlier: Difference between lock(locker) and lock(variable_which_I_am_using) I am looking at some code and trying to get my head around the locking thing and I am getting there I think. Now I noticed in some code I am reviewing that an object is created like so: private HashSet<Graphic> clustersInUse = new HashSet<Graphic>(); Then further in the code is used like so: lock

Intention Locks && Intention Locking Protocol

依然范特西╮ 提交于 2019-12-01 07:41:06
Intention Locks && Intention Locking Protocol http://dev.mysql.com/doc/refman/5.6/en/glossary.html#glos_intention_lock Intention Locks A kind of lock that applies to the table level, used to indicate what kind of lock the transaction intends to acquire on rows in the table. Different transactions can acquire different kinds of intention locks on the same table, but the first transaction to acquire an intention exclusive (IX) lock on a table prevents other transactions from acquiring any S or X locks on the table. Conversely(相反的), the first transaction to acquire an intention shared (IS) lock

PHP download blocks rest of requests

空扰寡人 提交于 2019-12-01 07:24:13
问题 I am downloading files from my server using a very simple script: header('Content-Description: File Transfer'); header('Content-Type: application/octet-stream'); header('Content-Disposition: attachment; filename='.basename($fichero)); header('Content-Transfer-Encoding: binary'); header('Expires: 0'); header('Cache-Control: must-revalidate, post-check=0, pre-check=0'); header('Pragma: public'); header('Content-Length: ' . filesize($file)); ob_clean(); flush(); readfile($file); It works fine,

SQL Server: how to acquire exclusive lock to prevent race condition?

混江龙づ霸主 提交于 2019-12-01 07:21:36
问题 I have the following T-SQL code: SET TRANSACTION ISOLATION LEVEL SERIALIZABLE BEGIN TRANSACTION T1_Test /*This is a dummy table used for "locking" and it doesn't contain any meaningful data.*/ UPDATE lockTable SET ID = 1 WHERE ID = 1 DECLARE @Count TINYINT SELECT @Count = COUNT(*) FROM debugSP WAITFOR DELAY '00:00:5'; INSERT INTO debugSP (DateCreated, ClientId, Result) SELECT GETDATE(), @@SPID, @Count COMMIT TRANSACTION T1_Test I am using "locking" hack marked with comment to acquire the

Can several threads hold a lock on the same monitor in Java?

和自甴很熟 提交于 2019-12-01 06:53:04
Currently we are analyzing a tomcat thread dump. A single thread dump of all threads running at that same time on a tomcat contains the following lines: ... "soldOutJmsConsumerContainer-1" prio=10 tid=0x00007f8409c14800 nid=0x231 in Object.wait() [0x00007f8403a9f000] java.lang.Thread.State: WAITING (on object monitor) at java.lang.Object.wait(Native Method) at java.lang.Object.wait(Object.java:485) at com.tc.object.RemoteObjectManagerImpl.waitUntilRunning(RemoteObjectManagerImpl.java:150) at com.tc.object.RemoteObjectManagerImpl.basicRetrieve(RemoteObjectManagerImpl.java:216) - locked

What happens when two threads ATTEMPT to lock the same resource at the exact same time?

房东的猫 提交于 2019-12-01 06:52:00
What happens when two threads attempt to lock the same object at the exact same microsecond (or whatever is the smallest length of time a CPU slice or instruction can be measured at)? Is it even possible for two threads to execute instructions at the exact same concurrent time, or is that an impossibility with today's hardware? Im working on a project that deals with muitithreading, where any thread may beat the other to the finish line, so to speak. So naturally, the question of "What happens when they all lock at the same time?" has to be addressed IMO. Modern locks, in pretty much all

Add new column without table lock?

眉间皱痕 提交于 2019-12-01 06:50:16
In my project having 23 million records and around 6 fields has been indexed of that table. Earlier I tested to add delta column for Thinking Sphinx search but it turns in holding the whole database lock for an hour. Afterwards when the file is added and I try to rebuild indexes this is the query that holds the database lock for around 4 hours: "update user_messages set delta = false where delta = true" Well for making the server up I created a new database from db dump and promote it as database so server can be turned live. Now what I am looking is that adding delta column in my table with

Unexpected behavior using std::try_to_lock

一个人想着一个人 提交于 2019-12-01 06:47:11
I get surprising and conflicting behavior when I try to run the following code. #include <iostream> #include <mutex> int main() { std::mutex mtx; std::unique_lock<std::mutex> lock1(mtx); std::unique_lock<std::mutex> lock2(mtx, std::try_to_lock); std::cout << "lock1 owns lock: " << lock1.owns_lock() << std::endl; std::cout << "lock2 owns lock: " << lock2.owns_lock() << std::endl; } When I run this on my computer (linux with either clang++ 4.0.1 or g++ 7.3.0) it prints out that both lock1 and lock2 own the lock (surprising). When I run this on cpp.sh it says that lock1 does own, but lock2 does

Hibernate versioning parent entity

一个人想着一个人 提交于 2019-12-01 06:45:32
Consider two entities Parent and Child. Child is part of Parent's transient collection Child has a ManyToOne mapping to parent with FetchType.LAZY Both are displayed on the same form to a user. When user saves the data we first update Parent instance and then Child collection (both using merge). Now comes the tricky part. When user modifies only Child property on the form then hibernate dirty checking does not update Parent instance and thus does not increase optimistic locking version number for that entity. I would like to see situation where only Parent is versioned and every time I call