All Questions

638
votes
17answers
374279 views

What is a race condition?

When writing multi-threaded applications, one of the most common problems experienced are race conditions. My questions to the community are: What is a race condition? How do you detect them? How ...
36
votes
2answers
15204 views

SQL Server Process Queue Race Condition

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 stor...
33
votes
2answers
10654 views

Atomic UPDATE .. SELECT in Postgres

I'm building a queuing mechanism of sorts. There are rows of data that need processing, and a status flag. I'm using an update .. returning clause to manage it: UPDATE stuff SET computed = 'working' ...
21
votes
4answers
46712 views

MySQL INSERT IF (custom if statements)

First, here's the concise summary of the question: Is it possible to run an INSERT statement conditionally? Something akin to this: IF(expression) INSERT... Now, I know I can do this with a stored...
19
votes
3answers
8825 views

How to make sure there is no race condition in MySQL database when incrementing a field?

How to prevent a race condition in MySQL database when two connections want to update the same record? For example, connection 1 wants to increase "tries" counter. And the second connection wants to ...
23
votes
4answers
10510 views

Do database transactions prevent race conditions?

It's not entirely clear to me what transactions in database systems do. I know they can be used to rollback a list of updates completely (e.g. deduct money on one account and add it to another), but i...
18
votes
1answers
3233 views

Can we have race conditions in a single-thread program?

You can find on here a very good explanation about what is a race condition. I have seen recently many people making confusing statements about race conditions and threads. I have learned that race ...
23
votes
4answers
1603 views

Why would try/finally rather than a "using" statement help avoid a race condition?

This question relates to a comment in another posting here: Cancelling an Entity Framework Query I will reproduce the code example from there for clarity: var thread = new Thread((param) => ...
2
votes
3answers
211 views

Hidden threads in Javascript/Node that never execute user code: is it possible, and if so could it lead to an arcane possibility for a race condition?

See bottom of question for an update, based on comments/answers: This question is really about the possibility of hidden threads that do not execute callbacks. I have a question about a potential a...
29
votes
6answers
11532 views

Race conditions in django

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): ...

Previous Next