Skip to main content
The 2024 Developer Survey results are live! See the results

Questions tagged [concurrency]

In computer science, concurrency is a property of systems in which multiple computations can be performed in overlapping time periods. The computations may be executing on multiple cores in the same chip, preemptively time-shared threads on the same processor, or executed on physically separated processors.

concurrency
172 votes
5 answers
75k views

When to use volatile with multi threading?

If there are two threads accessing a global variable then many tutorials say make the variable volatile to prevent the compiler caching the variable in a register and it thus not getting updated ...
David Preston's user avatar
1507 votes
24 answers
1.2m views

How do I use threading in Python?

I would like a clear example showing tasks being divided across multiple threads.
albruno's user avatar
  • 15.2k
1334 votes
19 answers
892k views

What is a race condition?

When writing multithreaded applications, one of the most common problems experienced is race conditions. My questions to the community are: What is the race condition? How do you detect them? How do ...
bmurphy1976's user avatar
  • 30.6k
62 votes
5 answers
15k views

Why is integer assignment on a naturally aligned variable atomic on x86?

I've been reading this article about atomic operations, and it mentions 32-bit integer assignment being atomic on x86, as long as the variable is naturally aligned. Why does natural alignment assure ...
timlyo's user avatar
  • 2,256
1198 votes
16 answers
1.0m views

Collection was modified; enumeration operation may not execute

I can't get to the bottom of this error, because when the debugger is attached, it does not seem to occur. Collection was modified; enumeration operation may not execute Below is the code. This is a ...
cdonner's user avatar
  • 37.5k
695 votes
13 answers
145k views

Is JavaScript guaranteed to be single-threaded?

JavaScript is known to be single-threaded in all modern browser implementations, but is that specified in any standard or is it just by tradition? Is it totally safe to assume that JavaScript is ...
Egor Pavlikhin's user avatar
154 votes
12 answers
80k views

How to limit the amount of concurrent async I/O operations?

// let's say there is a list of 1000+ URLs string[] urls = { "http://google.com", "http://yahoo.com", ... }; // now let's send HTTP requests to each of these URLs in parallel urls.AsParallel().ForAll(...
Grief Coder's user avatar
  • 6,736
1617 votes
41 answers
396k views

What is the difference between concurrency and parallelism?

What is the difference between concurrency and parallelism?
StackUnderflow's user avatar
254 votes
14 answers
210k views

What's the difference between Thread start() and Runnable run()

Say we have these two Runnables: class R1 implements Runnable { public void run() { … } … } class R2 implements Runnable { public void run() { … } … } Then what's the difference ...
Ori Popowski's user avatar
  • 10.6k
16 votes
4 answers
3k views

Will two atomic writes to different locations in different threads always be seen in the same order by other threads?

Similar to my previous question, consider this code -- Initially -- std::atomic<int> x{0}; std::atomic<int> y{0}; -- Thread 1 -- x.store(1, std::memory_order_release); -- Thread 2 -- y....
levzettelin's user avatar
  • 2,792
492 votes
16 answers
296k views

Custom thread pool in Java 8 parallel stream

Is it possible to specify a custom thread pool for Java 8 parallel stream? I can not find it anywhere. Imagine that I have a server application and I would like to use parallel streams. But the ...
Lukas's user avatar
  • 14.1k
407 votes
7 answers
141k views

What is a good pattern for using a Global Mutex in C#?

The Mutex class is very misunderstood, and Global mutexes even more so. What is good, safe pattern to use when creating Global mutexes? One that will work Regardless of the locale my machine is in ...
Sam Saffron's user avatar
80 votes
7 answers
46k views

Only inserting a row if it's not already there

I had always used something similar to the following to achieve it: INSERT INTO TheTable SELECT @primaryKey, @value1, @value2 WHERE NOT EXISTS (SELECT NULL FROM ...
Adam's user avatar
  • 952
9 votes
1 answer
7k views

Random errors when changing series using JFreeChart

I'm making a GUI that display result of background calculations. But before that, I wanted to test changing the dataset. Here is my code: DefaultXYDataset dataset = new DefaultXYDataset(); @Override ...
aragornsql's user avatar
464 votes
27 answers
445k views

How to wait for all threads to finish, using ExecutorService?

I need to execute some amount of tasks 4 at a time, something like this: ExecutorService taskExecutor = Executors.newFixedThreadPool(4); while(...) { taskExecutor.execute(new MyTask()); } //......
serg's user avatar
  • 111k

15 30 50 per page
1
2 3 4 5
210