FAQ Database Discussion Community


Is there a way to prevent two Python programs from executing the same binary at the same time?

python,race-condition
I have two Python scripts, that both need at regular intervals (think cronjobs) to call an external program. If this program (over which we have no control) is called twice simultaneously, data errors occur, so we need to have a way to synchronize calls to this binary. Is there a...

DOM Manipulation not executing instantly

javascript,dom,race-condition
I've experienced the issue that DOM Manipulations only take effect when the browser ran through all iterations, i.e. while, for, -loops. Example: var text = document.getElementById("text"); for (var i = 0; i < 100000000; i++) { if (i % 1000000 == 0) { setTimeout(function() { text.innerHTML += "|"; }, 0);...

Avoiding race conditions for a custom get_or_create in Django?

mysql,django,race-condition
Can anyone advise on the following problem: I have a custom get_or_create method, which checks multiple fields and does some fancy stuff upon creation: def fancy_get_or_create(name): object = self.fancy_get(name) if not object: object = self.fancy_create(name) return object def fancy_get(name): return self.filter(Q(name=name) | Q(alias=name)).first() def fancy_create(name): name = self.some_preprocessing(name) return self.create(name=name,...

Can POSIX/Linux unlink file entries completely race free?

linux,file-io,path,posix,race-condition
POSIX famously lets processes rename and unlink file entries with no regard as to the effects on others using them, whilst Windows by default raises an error if you even try to touch the timestamps of a directory which has a file handle open somewhere deep inside inside. However Windows...

Possible bug in Java 8 Update 45 on Windows 8

java,image,rgb,race-condition,compiler-bug
This code takes an input image and produces an output image dimensioned twice as large. The first four lines in the inner loop write four identical-sized copies of the original, the last four lines should overwrite the small images with one copy of the input image twice as large as...

Javascript - avoiding asynchronous race condition when checking object property existence

javascript,object,asynchronous,properties,race-condition
Whilst JavaScript might not be multi-threaded, it does support asynchronous execution and whilst executions for 2 or more asynchronous bits of code might be on the same thread, the fact that an asynchronous order of events cannot be predicted, makes it possible for a race condition between asynchronous executions to...

Race condition in Clojure stm?

clojure,race-condition,stm
Hello I was reading the book joy of clojure and in the section about the STM they have an image of 2 transactions where A is initially retrieving the same value from a ref as B is and then both transaction A and B does their calculations but A finishes...

Is it safe to read a weak pointer while it's being deallocated?

objective-c,automatic-ref-counting,race-condition
Is it safe to read a nonatomic weak pointer from a different thread than the object is being deallocated from? In general, I know properties should be made atomic whenever there may be simultaneous accesses, at least one of which is a write operation. But I have to wonder if...

C multithread program behaviour explanation

c,multithreading,race-condition
int g_ant = 0; void *writeloop(void *arg) { while(g_ant < 10) { g_ant++; usleep(rand()%10); printf("%d\n", g_ant); } exit(0); } int main(void) { pthread_t time; pthread_create(&time, NULL, writeloop, NULL); writeloop(NULL); pthread_join(time, NUL); return 0; } Hi! I have four questions which I believe goes under the category race condition...? :-) I'm...

chrome.webrequest.onCompleted vs. chrome.runtime.onMessage race

javascript,google-chrome,google-chrome-extension,race-condition
I have a Chrome extension with a background.js where information about a page is collected and stored, chrome.webRequest.onCompleted.addListener( function(details) { // compute a page hash etc, store it tabToHash[details.tabId] = hash; }, { urls: ['*://*/*.pdf'], types: ['main_frame'] } ); and served to any other part of extension that asks for...

REST service and race conditions

java,rest,race-condition
Let's imagine a problem: I have a REST service, which is implemented using Java/MySQL/Spring and HTTP/JSON technologies. The clients of the REST service are mobile applications. So it's possible that someone will decompile the code and will get the API of the REST service. ( Yes, the code is obfuscated...

Avoiding a race condition in erlang

erlang,race-condition
Is this how you avoid a race condition? -module(b). -export([my_spawn/1]). my_spawn(Func) -> Pid = spawn(listener()), Pid ! {self(), spawn, Func}, receive {From, Desired_Pid} -> Desired_Pid end. listener() -> receive {From, spawn, Func} -> {Pid,Ref} = spawn_monitor(Func), From ! {self(), Pid}, receive {'DOWN',Ref, process, _, _} -> io:format("I lived for [calculated...

Modprobe mutiple instances of a kernel module to prevent race conditions (device tree)

linux-device-driver,kernel-module,race-condition,device-tree
I am writing a kernel module for an embedded Linux system. The module works fine and is automatically loaded by using the compatible entry in the device tree. It creates a device in /dev/, which i can access using ioctl massages. The module manages several discrete memory regions. Since the...

Best way to print information when debugging a race condition

c,debugging,gdb,printf,race-condition
I am debugging an application to fix a segmentation fault that I suspect to be caused by a race condition. I'd like to put some print statements in the code, but I know for experience that adding calls to printf is not recommended since this could change the behavior of...

Race Condition inside Parallel.Foreach with List

vb.net,list,task-parallel-library,race-condition,parallel.foreach
I need help on how to resolve this race condition. Below is the code: Task.Factory.StartNew(Sub() ' Do something... dim newPeople as new List(Of Person) dim myNames as ConcurrentBag(Of String) = GetNames() Parallel.ForEach(myNames, Sub(name) Dim person as new Person person.Name = name person.Gender = "MALE" newPeople.Add(person) GridView.BeginInvoke(Sub() GridView.DataSource = newPeople End...

Destruction of class with condition variable in wait

c++,multithreading,c++11,race-condition
My problem is as follows: I have a thread that waits for a condition variable. And I need to destroy this thread. It seems simple enough to do: ~myclass() { myConditionVariable.notifyAll(); myThread.join(); } However the problem doing this, is that the thread running the destructor may get halted, allowing for...

shuffling cards with Javascript and inconsistent array values?

javascript,arrays,race-condition
I'm building a little module in javascript to act like a pack of cards. My first method works but was quite simple, and so i wanted to create some shuffle methods that mimic the idea behind real world card shuffling. Amongst some other useful functions I've create riffle, overhand and...

Can RPUSH and LPUSH in Redis race?

transactions,redis,race-condition
The docs at redis.io on RPUSH and LPUSH aren't clear on whether or not these operations are still O(1) and transational when pushing multiple items. For example, if two clients perform an RPUSH to the same list with multiple items, can their items become interspersed and thus out of order?...

Problems with race conditions on ConcurrentHashMap

java,multithreading,concurrency,thread-safety,race-condition
I got a multithreaded application in which n threads write to an ConcurrentHashMap. Another n Threads read from that Map and copy its Value to a copy List. After that the original List is removed from the map. For some reason I always get a ConcurrentModificationException. I even tried to...

Javascript-Array returns different values from one line to another. But why? (Lazy console + my little bug)

javascript,arrays,firefox,scope,race-condition
(Turned out it was a combined thing: a lazy console, and my old code where I started using arrays in function calls instead of a single number and thus handing over references that lead to modification of the actual and original array.) I have problems with an array, that should...

Copy a file, but don't overwrite, without TOCTTOU issues in Python

python,race-condition,shutil
I know that if I want to copy a file in Python but not overwrite the destination I can use code like this: if os.path.exists(dest): raise Exception("Destination file exists!") else: shutil.copy2(src, dest) But the state of the world could change between the time I call os.path.exists and the time I...

thread::join() blocks when it shouldn't

multithreading,c++11,atomic,race-condition
To understand how to use atomics in C++11, I tried to following code snippet: #include <iostream> #include <thread> #include <atomic> using namespace std; struct solution { atomic<bool> alive_; thread thread_; solution() : thread_([this] { alive_ = true; while (alive_); }) { } ~solution() { alive_ = false; thread_.join(); } };...

Understanding why race condition happens when only one thread does the write operation

exception,c++11,race-condition,raii,stdatomic
I recently asked "Thrown object cannot be caught in a multi-threaded solution" and got the correct answer which works perfectly. However, I am still confused why there can be a race condition when only one thread does the write operation. Let me paste the original problematic code: #include <iostream> #include...

Bound wait to solve race condition

algorithm,process,operating-system,synchronization,race-condition
I am trying to Give a race condition example , then write an algorithm to impose synchronization and write an algorithm that implement the Bounded wait solution?! I tried the case of when two admins A and B in the school receive 2 students to register them if they hit...

Multiple process execution and Ordering issues in docker-compose

bash,process,zookeeper,race-condition,docker-compose
I am trying to launch a zookeeper server and a bootstrap process for my API and another process which has to consume data written by my API to the zookeeper server using docker-compose. Once I execute docker-compose up, my zookeeper server launches successfully and my bootstrap API is able to...

Race condition with scipy.weave.inline

python,parallel-processing,scipy,race-condition
Recently I've begun to receive SyntaxErrors when running parallel neural-network simulations using brian2. These are being raised by calls to scipy.weave.inline when it tries to evaluate lines of code in a cache file. The full description of the problem and my guess at its cause is here. And here is...

Array.pop Race Condition

ruby-on-rails,arrays,concurrency,race-condition,pop
3 users on the system simultaneously click buy ticket model class TicketInventory < ActiveRecord::Base serialize :ticket_roll, Array end ticket_roll is seeded with a range of numbers controller ticket_inventory = TicketInventory.find(1) ticket_roll = ticket_inventory.ticket_roll TicketInventory.transaction do @ticket = ticket_roll.pop ticket_inventory.save end They all get the same ticket. I have contemplated lock_version,...

ASP.net cache access causing Collection Modified exception in foreach loop

asp.net,linq,caching,locking,race-condition
Ok first things first. This is some exception information given by the support team. I know the line and code where it happens. It happens in a FirstOrDefault call over a dictionary obtained from cache. 1) Exception Information ********************************************* Exception Type: System.InvalidOperationException Message: Collection was modified; enumeration operation may not...

How to prevent a race condition when multiple processes attempt to write to and then read from a file at the same time

python,io,race-condition,python-import,python-os
I have the following code (simplified for clarity): import os import errno import imp lib_dir = os.path.expanduser('~/.brian/cython_extensions') module_name = '_cython_magic_5' module_path = os.path.join(lib_dir, module_name + '.so') code = 'some code' have_module = os.path.isfile(module_path) if not have_module: pyx_file = os.path.join(lib_dir, module_name + '.pyx') # THIS IS WHERE EACH PROCESS TRIES TO...

How can I ensure I dont run into this race condition?

c#,sql-server,race-condition,azure-webjobssdk,azure-storage-queues
My current process is running in the following manner: 1.) A user enters a URL in the front end app for analyzing 2.) The front end validates the URL and creates a record of the URL in a table containing attributes of the URL 3.) The front end creates/updates a...

Singleton application with vector member

c++,c++11,singleton,compiler-optimization,race-condition
I have a Singleton application server (assume being created correctly). The server class has a non static vector member which is modified in several methods. Is it possible that the compiler optimizes the code such that the vector is modified non serially across several request processing method chains. I mean...