I have the following (javascript/jquery) code to show a busy indicator (after a delay) while an image is loading:
function imgUpdate(arg) {
var loaded = false;
$("#image").one("load", function(){
loaded = true;
$("#busyIndicator").hide();
});
setTimeout(function(){
if (!loaded) {
$("...
I have an order queue that is accessed by multiple order processors through a stored procedure. Each processor passes in a unique ID which is used to lock the next 20 orders for its own use. The stored procedure then returns these records to the order processor to be acted upon.
There are cases where multiple processors are able to ret...
I want to monitor all the open windows under X11. Currently, I'm doing this as follows:
Initially walking the whole tree by recursively calling XQueryTree from the root window
Listening for substructure changes on the whole desktop: XSelectInput( display, root_window, SubstructureNotifyMask | PropertyChangeMask )
Handling all MapNo...
Here is a simple example of a django view with a potential race condition:
# myapp/views.py
from django.contrib.auth.models import User
from my_libs import calculate_points
def add_points(request):
user = request.user
user.points += calculate_points(user)
user.save()
The race condition should be fairly obvious: A user can...
Today I came across this question:
you have a code
static int counter = 0;
void worker() {
for (int i = 1; i <= 10; i++)
counter++;
}
If worker would be called from two different threads, what value will counter have after both of them are finished?
I know that actually it could be anything. But my internal guts tells me...
(I'm interested in the .NET CLR)
What exactly happens when one thread changes the object a variable references while another thread is executing a method on the original object?
For example, say the type Foo has a variable 'Bar' of the type Bar, and Bar has no class-level state (for now at least, I'd like to keep this scenario simple)...
Hi,
I have run into some bugs into one of the boost components that I am using. After analyzing the problem a bit, I've found that I was not the only one, and the author had already issued a fix that is available in the boost SVN trunk.
What would be the best approach if I wanted to update just this component and reuse the libraries th...
I can't believe this - someone actually created two accounts on my social networking website using the same email even though there are both server sided as well as client sided validation checks that prevent such a thing from happening. But get this the time noted in the creation of both the accounts are exactly the same time.
For some...
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 destinatio...
I'm having a problem with the jQuery validate plugin and the remote validation rule, used in combination with the jQuery form plugin.
So I use the jQuery form plugin to intercept to form submition and if the validation fails, the form is not submitted. However, if the remote rule is already being validated (waiting for an answer from th...
My wordpress plugin has a table with a AUTO_INCREMENT primary key field called ID. When a new row is inserted into the table, I'd like to get the ID value of the insertion.
The feature is to using AJAX to post data to server to insert into DB. The new row ID is returned in the AJAX response to update client status. It is possible that ...
I have a urllib2 caching module, which sporadically crashes because of the following code:
if not os.path.exists(self.cache_location):
os.mkdir(self.cache_location)
The problem is, by the time the second line is being executed, the folder may exist, and will error:
File ".../cache.py", line 103, in __init__
os.mkdir(self.ca...
I'm trying to atomically increment a simple counter in Django. My code looks like this:
from models import Counter
from django.db import transaction
@transaction.commit_on_success
def increment_counter(name):
counter = Counter.objects.get_or_create(name = name)[0]
counter.count += 1
counter.save()
If I understand Django c...
Under what circumstances is it unsafe to have two different threads simultaneously writing to adjacent elements of the same array on x86? I understand that on some DS9K-like architectures with insane memory models this can cause word tearing, but on x86 single bytes are addressable. For example, in the D programming language real is a...
On most common platforms (the most important being x86; I understand that some platforms have extremely difficult memory models that provide almost no guarantees useful for multithreading, but I don't care about rare counter-examples), is the following code safe?
Thread 1:
someVariable = doStuff();
atomicSet(stuffDoneFlag, 1);
Thread...
In APUE section 8.3 fork function, about file sharing between parent and child processes,
It said: It is important that the parent and the child share the same file offset.
And in section 8.9 Race Conditions, there is a example: both parent and child write to
a file which is opened before invoking fork function. The program contains a...
We have a requirement to process transactions as an ordered sequence. Transactions are initiated
on system 'A' and written to a DB/2 table. A DB/2 trigger then forwards
the transaction via MQSeries to system 'B' where the transaction is completed.
The problem we are having is that a race condition is established because execution
of the...
Hi
I have something wich looks to me like race condition while logging to file from
multiple thread.
1) I've got a custom logger class (ConfigurableTraceLogger) that is shared by multiple threads in my application.
It's has lots of wrapper functions which all call to main core function
protected void TraceData(String category, TraceEv...
I am looking to monitor a folder for create events using the FileSystemWatcher in c#. The problem is that another 3rd party process is also watching that folder, I need (if possible) for my process to receive the create event before the 3rd party process.
Is there a way in managed or unmanaged code that I can give my process a higher pr...
I am having a problem with a race condition when saving to the database asynchronously using NHibernate. First an insert to the database is done asynchronously where the unique id is auto-generated. Before this insert returns back to the main thread with now persisted object that has the unique database generated id, the object in upda...