locking

Mysql select for update - it is not locking the target rows. How do I make sure it does?

守給你的承諾、 提交于 2021-02-19 02:22:26
问题 So the syntax for select for update is something like SELECT * //1st query FROM test WHERE id = 4 FOR UPDATE; UPDATE test //2nd query SET parent = 100 WHERE id = 4; I am guessing the locking part is the first line. So when the first set of queries executes, I should not be able to select and modify the row with id = 4 (it is primary key by the way). However, I am still able to select row with id = 4 before I update anything, meaning another thread could probably come in and try to select and

Lock a function from another function in java

丶灬走出姿态 提交于 2021-02-17 05:13:56
问题 I need lock a function from another function in java. In example above, I call slave function to print counter. And I need when that if master function called, all threads which calls slave function must be wait master functions to be ended. How can I do that? int counter = 0; private void slave() { System.out.println(counter); } private void master() { lockSlave(); counter ++; unlockSlave(); } 回答1: Take a look at JDK ReentrantReadWriteLock. private final ReadWriteLock lock = new

does the atomic instruction involve the kernel

我是研究僧i 提交于 2021-02-11 07:05:54
问题 I'm reading this link to learn about futex of Linux. Here is something that I don't understand. In order to acquire the lock, an atomic test-and-set instruction (such as cmpxchg()) can be used to test for 0 and set to 1. In this case, the locking thread acquires the lock without involving the kernel (and the kernel has no knowledge that this futex exists). When the next thread attempts to acquire the lock, the test for zero will fail and the kernel needs to be involved. I don't quite

does the atomic instruction involve the kernel

六眼飞鱼酱① 提交于 2021-02-11 07:05:49
问题 I'm reading this link to learn about futex of Linux. Here is something that I don't understand. In order to acquire the lock, an atomic test-and-set instruction (such as cmpxchg()) can be used to test for 0 and set to 1. In this case, the locking thread acquires the lock without involving the kernel (and the kernel has no knowledge that this futex exists). When the next thread attempts to acquire the lock, the test for zero will fail and the kernel needs to be involved. I don't quite

does the atomic instruction involve the kernel

三世轮回 提交于 2021-02-11 07:04:45
问题 I'm reading this link to learn about futex of Linux. Here is something that I don't understand. In order to acquire the lock, an atomic test-and-set instruction (such as cmpxchg()) can be used to test for 0 and set to 1. In this case, the locking thread acquires the lock without involving the kernel (and the kernel has no knowledge that this futex exists). When the next thread attempts to acquire the lock, the test for zero will fail and the kernel needs to be involved. I don't quite

Locking and concurrent executions of a stored procedure

那年仲夏 提交于 2021-02-10 22:40:54
问题 I have a stored procedure that is executed by remote clients on an ongoing basis. From reading the docs I am under the impression that with the proper locking techniques I shouldn't need to externally manage these clients and I would be free to have them run as often and as concurrently as they like. This procedure updates and inserts to multiple tables. A skeleton outline of the procedure is below: LOCK TABLE table1 IN EXCLUSIVE MODE; LOOP UPDATE table1 SET "var1"="var1"+1, WHERE "var2"=var2

Locking and concurrent executions of a stored procedure

半腔热情 提交于 2021-02-10 22:40:30
问题 I have a stored procedure that is executed by remote clients on an ongoing basis. From reading the docs I am under the impression that with the proper locking techniques I shouldn't need to externally manage these clients and I would be free to have them run as often and as concurrently as they like. This procedure updates and inserts to multiple tables. A skeleton outline of the procedure is below: LOCK TABLE table1 IN EXCLUSIVE MODE; LOOP UPDATE table1 SET "var1"="var1"+1, WHERE "var2"=var2

Is INSERT … SELECT an atomic transaction?

梦想与她 提交于 2021-02-10 18:15:40
问题 I use a query like this: INSERT INTO table SELECT * FROM table2 t2 JOIN ... ... WHERE table2.date < now() - '1 day'::INTERVAL FOR UPDATE OF t2 SKIP LOCKED ON CONFLICT (...) DO UPDATE SET ... RETURNING *; My question is about FOR UPDATE t2 SKIP LOCKED . Should I use it here? Or will Postgres lock these rows automatically with INSERT SELECT ON CONFLICT till the end of the transaction? My goal is to prevent other apps from (concurrently) capturing rows with the inner SELECT which are already

Oracle SELECT FOR UPDATE - Demonstration?

南笙酒味 提交于 2021-02-10 14:23:09
问题 I am quite not understanding the lock functionality with SELECT FOR UPDATE. Here is what I've tried. CREATE TABLE ACCOUNT_TAB ( ACC_ID int NOT NULL PRIMARY KEY, BALANCE int NOT NULL ); INSERT INTO ACCOUNT_TAB VALUES(1, 100); SELECT * FROM ACCOUNT_TAB FOR UPDATE; SELECT * FROM ACCOUNT_TAB; Both SELECT will retrieve the row, but shouldn't the first query lock the row in the ACCOUNT_TAB table? I have read something about sessions: queries from the same session don't care about the lock. Can I

How to lock/unlock a file across process?

烈酒焚心 提交于 2021-02-08 14:22:59
问题 Using C# running on mono on Linux, notice that below code works well on windows can lock a file across process but not on linux via mono (ubuntu 14.04) new FileStream("myfile.lock",FileMode.OpenOrCreate,FileAccess.ReadWrite,FileShare.None); research from internet, i should be able to do it with advisory lock FileStream.Lock however, it doesn`t work. tested with two processes on ubuntu 14.04, both of them can execute "FileStream.Lock(0, int.MaxValue)". i would expect the later one will fail