180
votes
Does it ever make sense to use more concurrent processes than processor cores?
The canonical time when you use far, far more processes than cores is when your processes aren't CPU bound. If your processes are I/O bound (either disk or more likely network), then you can ...
119
votes
Accepted
Is there a difference between fibers, coroutines and green threads and if that is so what is it?
A Fiber is a lightweight thread that uses cooperative multitasking instead of preemptive multitasking. A running fiber must explicitly "yield" to allow another fiber to run, which makes their ...
93
votes
Accepted
How does a single thread run on multiple cores?
The operating system offers time slices of CPU to threads that are eligible to run.
If there is only one core, then the operating system schedules the most eligible thread to run on that core for a ...
72
votes
What are the drawbacks of making a multi-threaded JavaScript runtime implementation?
1) Multithreading is extremely hard, and unfortunately the way you've presented this idea so far implies you're severely underestimating how hard it is.
At the moment, it sounds like you're simply "...
59
votes
Accepted
Why should your code not use 100% CPU?
If cooling is insufficient, the CPU might overheat. But they all (well, at least all modern PC CPUs) feature various thermal protection mechanisms which will throttle the clock speed or, as a final ...
58
votes
Does it ever make sense to use more concurrent processes than processor cores?
Short answer: Yes.
Longer answer:
Set your magic number stupid high, benchmark it, set it low, benchmark it again, and keep doing that until you have your answer.
The number of moving parts here is ...
46
votes
Accepted
Multithreading: am I doing it wrong?
One assumption you are making might not be valid: you require (among other things) that your threads execute simultaneously. Might work for 3, but at some point the system is going to need to ...
45
votes
Why would a program require a specific minimum number of CPU cores?
It may be possible to do this "by accident" with careless use of core affinity. Consider the following pseudocode:
start a thread
in that thread, find out which core it is running on
set its CPU ...
41
votes
Why is multithreading not used everywhere?
Why multithreading isn't everywhere?
Because …
I understand that multi-threading is hard to implement and has drawbacks if number of threads is less than expected.
37
votes
Accepted
What prevents a race condition on a lock?
Is it impossible, or just plain unlikely?
Impossible. It can be implemented in different ways, e.g., via the Compare-and-swap where the hardware guarantees sequential execution. It can get a bit ...
36
votes
Can someone explain in simple terms what is the disruptor pattern?
The Fowler Article providers a good primer, and this explanation:
At a crude level you can think of a Disruptor as a multicast graph of
queues where producers put objects on it that are sent to all ...
34
votes
Why would a program require a specific minimum number of CPU cores?
It could be necessary to have 4 cores because the application runs four tasks in parallel threads and expects them to finish almost simultaneously.
When every thread is executed by a separate core ...
30
votes
Why coroutines are back?
Coroutines never left, they were just overshadowed by other things in the meanwhile. The recently increased interest in asynchronous programming and therefore coroutines is largely due to three ...
29
votes
Best way to define, start and stop threads in C#
I am making a little program, which have few Threads, constantly running. At some point, I may want to stop one of them, and then, after random period of time, to start it again. What is the best way ...
28
votes
Accepted
Programs that claim they are not "multi-core" friendly
Good concurrency requires a lot more than throwing a few threads in an application and hoping for the best. There's a range in how concurrent a program can be going from embarrassingly parallel to ...
28
votes
Accepted
how many cores should I utilize for calculations? #cores or #cores -1?
Major operating systems are mature enough to know how to handle processes which use every available core. Other processes may (and often will) be affected, but the computation won't become slower ...
28
votes
Accepted
Why is multithreading not used everywhere?
The proliferation of multi-core CPUs is predominantly driven by supply, not by demand.
You're right that many programmers don't bother decomposing their systems so that they can profit from multiple ...
27
votes
How does a single thread run on multiple cores?
There is no such thing as a single thread running on multiple cores simultaneously.
It doesn't mean, however, that instructions from one thread cannot be executed in parallel. There are mechanisms ...
25
votes
Why is it the caller's responsibility to ensure thread safety in GUI programming?
Because making the GUI lib thread safe is a massive headache and a bottleneck.
Control flow in GUIs often goes in 2 directions from the event queue to root window to the gui widgets and from the ...
25
votes
How does a single thread run on multiple cores?
summary: Finding and exploiting the (instruction-level) parallelism in a single-threaded program is done purely in hardware, by the CPU core it's running on. And only over a window of a couple ...
25
votes
Why do modern operating systems *ever* have perceptible input (keyboard/mouse) lag?
As you may have noticed, there's a category of application that tries really hard to avoid input lag and only occasionally fails at doing so: games. Even then it's not uncommon for players to notice ...
24
votes
Why do modern operating systems *ever* have perceptible input (keyboard/mouse) lag?
I would like to answer this question from more of a high-level, marketing perspective than a more low-level, technical one.
All of the current mainstream Operating Systems are so-called general ...
23
votes
Why is multithreading not used everywhere?
Why multithreading isn't everywhere?
Frame challenge: but it is everywhere.
Let's see, let's name some platforms:
Desktops/laptops: one of the most common applications today is the browser. And to ...
22
votes
Accepted
Why is it the caller's responsibility to ensure thread safety in GUI programming?
Toward the end of his failed dream essay, Graham Hamilton (a major Java architect) mentions if developers "are to preserve the equivalence
with an event queue model, they will need to follow various
...
21
votes
Accepted
Mutex vs Semaphore: How to implement them _not_ in terms of the other?
I think your question is more about what primitives are used to implement those, and the answer is - it depends. I will try to focus on modern implementations.
First, Linux uses futex syscall (Fast ...
20
votes
How to prevent two users from registering at the same instant with same username?
Let's say the database doesn't contain username 'user1'. When two
users try to register at the same moment with 'user1' it'll accept it.
Why would it accept it? It's simple to apply a unique ...
20
votes
Why do modern operating systems *ever* have perceptible input (keyboard/mouse) lag?
Why can't (or why don't) operating systems absolutely prioritise user input (and repainting thereof) in threading and process scheduling?
Even if the operating system tells the application about the ...
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
multithreading × 655java × 118
concurrency × 98
c# × 85
c++ × 70
design × 50
c × 37
architecture × 30
design-patterns × 29
.net × 28
performance × 25
python × 24
locks × 21
operating-systems × 19
synchronization × 19
asynchronous-programming × 19
cpu × 17
parallelism × 17
c++11 × 15
async × 15
multiprocessing × 15
multi-core × 14
parallel-programming × 13
algorithms × 12
linux × 12