race-condition

Ways to Find a Race Condition

◇◆丶佛笑我妖孽 提交于 2019-12-03 15:20:23
问题 I have a bit of code with a race condition in it... I know that it is a race condition because it does not happen consistently, and it seems to happen more often on dual core machines. It never happens when I'm tracing. Although, there is a possibility that it could be a deadlock as well. By analyzing stages of completion of logs where this does and does not occur, I've been able to pinpoint this bug to a single function. However, I do not know where in the scope of the function this is

Simulating race conditions in RSpec unit tests

会有一股神秘感。 提交于 2019-12-03 14:38:55
问题 We have an asynchronous task that performs a potentially long-running calculation for an object. The result is then cached on the object. To prevent multiple tasks from repeating the same work, we added locking with an atomic SQL update: UPDATE objects SET locked = 1 WHERE id = 1234 AND locked = 0 The locking is only for the asynchronous task. The object itself may still be updated by the user. If that happens, any unfinished task for an old version of the object should discard its results as

Best way to prevent race condition in multiple chrome.storage API calls?

荒凉一梦 提交于 2019-12-03 13:24:38
问题 Something requests a task Something else pulls the task list out of storage, and checks if there are tasks there. If there are tasks it removes one and the smaller "task list" is put back in storage. Between steps 2 and 3 a race condition can occur if multiple requests occur, and the same task will be served twice. Is the correct resolution to "lock" the "tasks table" while a single task is "checked out", to prevent any other requests? What is the solution with the least performance impact,

Cache consistency when using memcached and a rdbms like MySQL

放肆的年华 提交于 2019-12-03 12:07:52
I have taken a database class this semester and we are studying about maintaining cache consistency between the RDBMS and a cache server such as memcached. The consistency issues arise when there are race conditions. For example: Suppose I do a get(key) from the cache and there is a cache miss. Because I get a cache miss, I fetch the data from the database, and then do a put(key,value) into the cache. But, a race condition might happen, where some other user might delete the data I fetched from the database. This delete might happen before I do a put into the cache. Thus, ideally the put into

How to correctly use sync.Cond?

你。 提交于 2019-12-03 11:00:52
问题 I'm having trouble figuring out how to correctly use sync.Cond. From what I can tell, a race condition exists between locking the Locker and invoking the condition's Wait method. This example adds an artificial delay between the two lines in the main goroutine to simulate the race condition: package main import ( "sync" "time" ) func main() { m := sync.Mutex{} c := sync.NewCond(&m) go func() { time.Sleep(1 * time.Second) c.Broadcast() }() m.Lock() time.Sleep(2 * time.Second) c.Wait() } [Run

proper way to use lock file(s) as locks between multiple processes

冷暖自知 提交于 2019-12-03 10:08:36
问题 I have a situation where 2 different processes(mine C++, other done by other people in JAVA) are a writer and a reader from some shared data file. So I was trying to avoid race condition by writing a class like this(EDIT:this code is broken, it was just an example) class ReadStatus { bool canRead; public: ReadStatus() { if (filesystem::exists(noReadFileName)) { canRead = false; return; } ofstream noWriteFile; noWriteFile.open (noWriteFileName.c_str()); if ( ! noWriteFile.is_open()) { canRead

Multi-thread state visibility in Java: is there a way to turn the JVM into the worst case scenario?

吃可爱长大的小学妹 提交于 2019-12-03 09:08:47
问题 Suppose our code has 2 threads (A and B) have a reference to the same instance of this class somewhere: public class MyValueHolder { private int value = 1; // ... getter and setter } When Thread A does myValueHolder.setValue(7) , there is no guarantee that Thread B will ever read that value: myValueHolder.getValue() could - in theory - keep returning 1 forever. In practice however, the hardware will clear the second level cache sooner or later, so Thread B will read 7 sooner or later (usually

Working with a global singleton in Flask (WSGI), do I have to worry about race conditions?

喜夏-厌秋 提交于 2019-12-03 07:53:03
问题 The hello world demo for Flask is: from flask import Flask app = Flask(__name__) @app.route("/") def hello(): return "Hello World!" if __name__ == "__main__": app.run() What if I modified this like so: from flask import Flask app = Flask(__name__) a = 1 b = 2 c = 3 @app.route("/") def hello(): a += 1 b += a c += b return "Hello World!" if __name__ == "__main__": app.run() I understand WSGI application might have multiple threads. The hello function could be running on multiple threads at the

Simulating race conditions in RSpec unit tests

折月煮酒 提交于 2019-12-03 04:25:35
We have an asynchronous task that performs a potentially long-running calculation for an object. The result is then cached on the object. To prevent multiple tasks from repeating the same work, we added locking with an atomic SQL update: UPDATE objects SET locked = 1 WHERE id = 1234 AND locked = 0 The locking is only for the asynchronous task. The object itself may still be updated by the user. If that happens, any unfinished task for an old version of the object should discard its results as they're likely out-of-date. This is also pretty easy to do with an atomic SQL update: UPDATE objects

Preventing race condition of if-exists-update-else-insert in Entity Framework

荒凉一梦 提交于 2019-12-03 03:56:51
问题 I've been reading other questions on how to implement if-exists-insert-else-update semantics in EF, but either I'm not understanding how the answers work, or they are in fact not addressing the issue. A common solution offered is to wrap the work in a transaction scope (eg: Implementing if-not-exists-insert using Entity Framework without race conditions): using (var scope = new TransactionScope()) // default isolation level is serializable using(var context = new MyEntities()) { var user =