locking

Atomic struct containing pointer

拟墨画扇 提交于 2020-08-19 12:12:09
问题 #include <atomic> #include <iostream> using namespace std; struct Simple{ int a = 0; int b = 0; }; struct WithPointer{ int *a = nullptr; int b = 0; }; int main(int argc, char const *argv[]) { atomic<Simple> simple; cout<<simple.is_lock_free()<<"\n"; atomic<Simple*> simple_p; cout<<simple_p.is_lock_free()<<"\n"; atomic<WithPointer> with_pointer; cout<<with_pointer.is_lock_free()<<"\n"; return 0; } This example works fine for the Simple struct but not for the WithPointer struct. I get the

Transactions, locks, isolation levels

巧了我就是萌 提交于 2020-07-17 08:45:27
问题 I have a few questions regarding subject from the title. First of all, lets assume that we work with JDBC, and there we have 2 transactions T1 and T2. In T1 we execute select statement on one particular row. Then we execute update on that row. In transaction T2 we execute select statement on the same row. Here are the questions: 1) When does transaction T1 acquire the lock on mentioned row? I assume it happens during select statement execution? 2) How long transaction T1 holds the lock? Does

What's the closest we can get to `REFRESH COMPLETE ON COMMIT` in PostgresQL?

生来就可爱ヽ(ⅴ<●) 提交于 2020-06-29 04:03:12
问题 So we're looking for a way to enforce constraints that span multiple tables. We've come across this old blog post, which suggests: Create a materialized view to select data that violates the desired constraint. The MV must be defined with REFRESH COMPLETE ON COMMIT so that it is updated before the end of the transaction. Create a check constraint on the materialized view that always evaluates to FALSE – e.g. CHECK (1=0) That’s it. Whenever the underlying tables are updated, the materialized

What's the closest we can get to `REFRESH COMPLETE ON COMMIT` in PostgresQL?

心不动则不痛 提交于 2020-06-29 04:02:08
问题 So we're looking for a way to enforce constraints that span multiple tables. We've come across this old blog post, which suggests: Create a materialized view to select data that violates the desired constraint. The MV must be defined with REFRESH COMPLETE ON COMMIT so that it is updated before the end of the transaction. Create a check constraint on the materialized view that always evaluates to FALSE – e.g. CHECK (1=0) That’s it. Whenever the underlying tables are updated, the materialized

Postgres trigger and row locking

China☆狼群 提交于 2020-06-27 19:43:10
问题 Please help with my understanding of how triggers and locks can interact I bulk load records to a table with statements something like this….. BEGIN; INSERT INTO table_a VALUES (record1) , (record2), (record3)………; INSERT INTO table_a VALUES (record91) , (record92), (record93)………; ….. …. COMMIT; There can be several hundred records in a single insert, and there can be several dozen INSERT statements between COMMITs Table_a has a trigger on it defined as…. AFTER INSERT ON table_a FOR EACH ROW

How to lock objects withthe same ids?

别说谁变了你拦得住时间么 提交于 2020-06-25 09:43:07
问题 I have got the following code: public void Update(Foo foo) { lock(_locker) { UpdateFirstPart(foo.First); UpdateSecondPart(foo.Second); UpdateThirdPart(foo.Third); } } public class Foo { public int Id; public Some1 First; public Some2 Second; public Some3 Third; } Method Update can be performed in two or more threads and I use lock to prevent cuncurency problems with foo . But I would like to lock only those Foo that have similar Id . For instance if one thread executes method Update with Foo

Python: Why is the multiprocessing lock shared among processes here?

我与影子孤独终老i 提交于 2020-06-25 04:37:13
问题 I am trying to share a lock among processes. I understand that the way to share a lock is to pass it as an argument to the target function. However I found that even the approach below is working. I could not understand the way the processes are sharing this lock. Could anyone please explain? import multiprocessing as mp import time class SampleClass: def __init__(self): self.lock = mp.Lock() self.jobs = [] self.total_jobs = 10 def test_run(self): for i in range(self.total_jobs): p = mp

How to queue up calls to stored procedures in Oracle?

佐手、 提交于 2020-06-17 08:03:52
问题 I have a stored procedure in oracle (which schedules a one-time job to run another procedure, if this is relevant). The job calls another stored procedure which runs for a few minutes, and performs inserts updates and deletes and also uses loops. Now while the long procedure is running, if there is another call for it to run, is it possible to prevent them from executing simultaneously? And even better, to make the second one execute once the previous one has finished, like queue them? 回答1:

Distributed locking in .NET

萝らか妹 提交于 2020-06-10 04:42:27
问题 I'm looking for recommendations for a locking mechanism that will work across multiple machines. In my case I basically just want to be able to start a service on 2 machines and have one block until the other finishes as a simple way to insure redundancy in case a service machine goes down. Sort of along the same lines as Distributed Lock Service but specifically looking for projects that people have successfully integrated with .NET. 回答1: We use SqlServer's application lock functionality for

How to detect query which holds the lock in Postgres?

╄→гoц情女王★ 提交于 2020-06-09 07:23:26
问题 I want to track mutual locks in postgres constantly. I came across Locks Monitoring article and tried to run the following query: SELECT bl.pid AS blocked_pid, a.usename AS blocked_user, kl.pid AS blocking_pid, ka.usename AS blocking_user, a.query AS blocked_statement FROM pg_catalog.pg_locks bl JOIN pg_catalog.pg_stat_activity a ON a.pid = bl.pid JOIN pg_catalog.pg_locks kl ON kl.transactionid = bl.transactionid AND kl.pid != bl.pid JOIN pg_catalog.pg_stat_activity ka ON ka.pid = kl.pid