race-condition

Background Worker: Make sure that ProgressChanged method has finished before executing RunWorkerCompleted

喜欢而已 提交于 2019-12-06 14:13:44
Let's assume I'm using a Background Worker and I've the following methods: private void bw_DoWork(object sender, DoWorkEventArgs e) { finalData = MyWork(sender as BackgroundWorker, e); } private void bw_ProgressChanged(object sender, ProgressChangedEventArgs e) { int i = e.ProgressPercentage; // Missused for i Debug.Print("BW Progress Changed Begin, i: " + i + ", ThreadId: " + Thread.CurrentThread.ManagedThreadId); // I use this to update a table and an XY-Plot, so that the user can see the progess. UpdateGUI(e.UserState as MyData); Debug.Print("BW Progress Changed End, i: " + i + ", ThreadId:

Synchronize shell script execution

巧了我就是萌 提交于 2019-12-06 06:30:57
问题 A modified version of a shell script converts an audio file from FLAC to MP3 format. The computer has a quad-core CPU. The script is run using: ./flac2mp3.sh $(find flac -type f) This converts the FLAC files in the flac directory (no spaces in file names) to MP3 files in the mp3 directory (at the same level as flac ). If the destination MP3 file already exists, the script skips the file. The problem is that sometimes two instances of the script check for the existence of the same MP3 file at

java: race conditions - is there a way to make sure several lines of code will be executed together?

痞子三分冷 提交于 2019-12-06 05:17:45
I have a registration page that receives tokens ad parse them and login the user if the parameters apply. Between the time that i checked the token, to the time that i removed the token from the db, another user can use the same token to login. is there a way to make sure that specific range of lines of code will be executed with not interference, so i won't have race condition problem ? thanks update I have two servers. apache tomcat 6 red5 v0.9 (free java based flash media streaming and communication server) I'm writing a game application for Facebook. the game itself is written in adobe

Redis as unique atomic id generator - Thread safe way for web app to avoid race condition

青春壹個敷衍的年華 提交于 2019-12-06 04:09:04
I plan to use redis as an unique atomic id generator. However, my concern there might be simulatoneous web requests from multiple browsers. I was wondering, what is the common practice to make the following operations atomic? get id from redis if id is not found insert id as 0 into redis else store the id in a variable increase id by one store the new id back to redis If I were in desktop app or mobile app, I would use synchronized keyword in Java to avoid race condition . However, how about for a PHP web app? Assuming you're looking to generate sequential ids, you can use Redis and the INCR

Defending against race conditions in System.Collections.Concurrent.ConcurrentDictionary

ぐ巨炮叔叔 提交于 2019-12-06 04:07:36
问题 The .NET ConcurrentDictionary is susceptible to a race condition that may cause unexpected data as explained at the bottom of this MSDN article. I'm assuming that there are several factors to take into account. Q: How should I write code that is not vulnerable to that race condition that may cause data loss? In my scenario I have an input stream that has an always increasing index (n++). My thought is that I could detect missing data if the race condition occurs and re-send it. On the other

PL/pgSQL column name the same as variable

那年仲夏 提交于 2019-12-06 03:14:28
问题 I'm new to plpgsql and I'm trying to create function that will check if a certain value exists in table and if not will add a row. CREATE OR REPLACE FUNCTION hire( id_pracownika integer, imie character varying, nazwisko character varying, miasto character varying, pensja real) RETURNS TEXT AS $BODY$ DECLARE wynik TEXT; sprawdzenie INT; BEGIN sprawdzenie = id_pracownika; IF EXISTS (SELECT id_pracownika FROM pracownicy WHERE id_pracownika=sprawdzenie) THEN wynik = "JUZ ISTNIEJE"; RETURN wynik;

Signal handler accessing queue data structure (race condition?)

纵饮孤独 提交于 2019-12-06 00:22:01
问题 I'm currently writing a small shell in C++. Jobs and the PIDs associated with them are stored within a queue of job pointers (job *) . When a new job is run, information about it is added to the queue. Since multiple jobs can be handled simultaneously and new jobs can be entered at the shell's console at any time, I have a signal handler to wait on jobs which are terminated. When a job is terminated, I need to remove it's information from the active job queue and move it to my deque of

Get or create child Akka actor and ensure liveness

余生颓废 提交于 2019-12-06 00:20:50
问题 I am trying to use a hierarchy of Akka actors to handle per user state. There is a parent actor that owns all the children, and handles the get-or-create in the correct way (see a1, a2): class UserActorRegistry extends Actor { override def Receive = { case msg@ DoPerUserWork(userId, _) => val perUserActor = getOrCreateUserActor(userId) // perUserActor is live now, but will it receive "msg"? perUserActor.forward(msg) } def getOrCreateUserActor(userId: UserId): ActorRef = { val childName =

implementation of ajax status check

↘锁芯ラ 提交于 2019-12-05 19:18:55
I am battling with race condition protection in PHP. My application is written in symfony 1.4 and PHP locks session data until a page completes processing. I have a long running (~10 second) login script and I want to display a progress bar showing the user what is being done while they wait. (I want to actually display what is being done and not use a standard [faux] loading bar.) Whenever a script calls session_start() , PHP locks that user's session data until that script completes. This prevents my status check ajax calls from returning anything until the longer running script completes.

Condition Variable - Wait/Notify Race Condition

蹲街弑〆低调 提交于 2019-12-05 15:17:49
I'll present some code first since explaining is easier that way. Assume that mutexes are correctly used with the condition variables to keep it simple: // Thread 1 while(1) { conditionVariable.wait(); // Do some work } // Thread 2 while(1) { // Do some work conditionVariable.notify_one(); } // Thread 3 while(1) { // Do some work conditionVariable.notify_one(); } What I would like to achieve is that thread 1 is guaranteed to be waiting on the condition variable when thread 2 or Thread 3 notifies. As the code stands, there is a large gap between notify_one() and wait() in the form of some other