locking

Could there be a deadlock when using optimistic locking?

南笙酒味 提交于 2019-12-12 08:58:43
问题 As is known, there are two locking strategy: Optimistic vs. Pessimistic locking Pessimistic Locking is when you lock the record for your exclusive use until you have finished with it. It has much better integrity than optimistic locking but requires you to be careful with your application design to avoid Deadlocks. Also knonw, that Optimistic Concurrency Control is not the same as Multi Version Concurrency Control (Oracle or MSSQL-Snapshot/MVCC-RC): Optimistic vs Multi Version Concurrency

SQLite Connections & Locking

心已入冬 提交于 2019-12-12 08:31:48
问题 I'd like to access a SQLite database from 2 different threads, thereby using 2 different connections to the database. Both threads will mainly perform reads from the DB and will write to the DB only occasionally. If I feel the odds are against both threads writing to the DB at the same time, should I feel safe that I should not have any issues in this scenario ? 回答1: SQLite is threadsafe and, with recent versions, you can share a single connection among threads. That said, the SQLite FAQ

Java read & write lock requirement, with lock and release from different threads

独自空忆成欢 提交于 2019-12-12 08:14:57
问题 I'm trying to find a less clunky solution to a Java concurrency problem. The gist of the problem is that I need a shutdown call to block while there are still worker threads active, but the crucial aspect is that the worker tasks are each spawned and completed asynchronously so the hold and release must be done by different threads. I need them to somehow send a signal to the shutdown thread once their work has completed. Just to make things more interesting, the worker threads cannot block

“Atomically” update an entire array

我怕爱的太早我们不能终老 提交于 2019-12-12 07:56:51
问题 I have a single writer thread and single reader thread to update and process a pool of arrays(references stored in map). The ratio of writes to read is almost 5:1(latency of writes is a concern). The writer thread needs to update few elements of an array in the pool based on some events. The entire write operation(all elements) needs to be atomic. I want to ensure that reader thread reads the previous updated array if writer thread is updating it(something like volatile but on entire array

Know when to show a passcode lock

£可爱£侵袭症+ 提交于 2019-12-12 07:12:10
问题 I am developing an application that needs to display a passcode screen whenever a user leaves the app and comes back (be it through a screen lock, or going back to the home screen through the back or home button). I had it working using the following: The starting activity would call for the passcode check on startup, and each activity added the following functionality to their onPause method: @Override public void onPause() { super.onPause(); if (!isFinishing()) { new PasscodeCheckTask(this

Intel 64 and IA-32 | Atomic operations including acquire / release semantic

风格不统一 提交于 2019-12-12 07:10:08
问题 According to the Intel 64 and IA-32 Architectures Software Developer's Manual the LOCK Signal Prefix "ensures that the processor has exclusive use of any shared memory while the signal is asserted". That can be a in the form of a bus or cache lock. But - and that's the reason I'm asking this question - it isn't clear to me, if this Prefix also provides any memory-barrier. I'm developing with NASM in a multi-processor environment and need to implement atomic operations with optional acquire

Acquire_lock() not working. Bot still sending requests quickly. PHP + AJAX

别等时光非礼了梦想. 提交于 2019-12-12 06:18:20
问题 I posted a question yesterday about someone using a bot to exploit my betting site and press "Roll" multiple times very quickly, to get the same roll numbers. Stop bot sending multiple requests quickly. PHP + AJAX The answer someone gave me was to use locking. So I did, but he came back and it didn't work. See below: Can someone look at my code and tell me what I'm doing wrong or if it's just not enough. The page sends the request using ajax, you can find the code on the previous question as

Is it okay to to make the lock transient for a Serializable class?

萝らか妹 提交于 2019-12-12 05:28:04
问题 I have a class that implements Serializable and I protect the invariant of this class via a lock object which is of type Object . Is it okay to make it transient or can it have any unwanted side effects? Code : class MyClass implements Serializable{ private final transient lock = new Object(); .... } 回答1: This is fine, as long as you recreate the object upon de-serialization so that you have something to synchronize on. Also, you'll probably have to remove the final modifier. It's up to you

Lock a line in QTextEdit

≡放荡痞女 提交于 2019-12-12 05:17:49
问题 How can I lock a line(or a part of a line) in a "QTextEdit" control? I can do this: when I move the cursor position at that part of the line, the cursor will be moved automatically to the next first position that not belongs to that part of the line. Maybe you have antoher idea. Thank you! 回答1: I would connect to the QTextEdit::cursorPositionChanged() and handle the movement there. http://qt-project.org/doc/qt-4.8/qtextcursor.html#position http://qt-project.org/doc/qt-4.8/qtextedit.html

Do we need to have static lock for static member variable of the class in c++

被刻印的时光 ゝ 提交于 2019-12-12 05:16:31
问题 I have a static map as a member variable of my class. Do we need to have static lock when we have to access this map? 回答1: If your std::map instance is declared class static, then your lock needs to be class static too. Consider two threads working against separate objects using the map when the lock is a non static member but the map is. Object 1 locks the local lock and starts manipulating the shared map. Object 2 locks its local lock (it's a separate lock, remember) and starts manipulating