182
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 ...
95
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 ...
71
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
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 ...
51
votes
Accepted
What causes unpredictability when doing multi threading
Your understanding of computer hardware is flawed. Memory is not accessed by different cores in parallel, access is regulated like traffic at a road junction. Different threads can run simultaneously ...
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.
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
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 ...
29
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 ...
29
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 ...
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 ...
26
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 ...
25
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 ...
20
votes
Accepted
How does sleeping a thread work?
There is much more involved in running a program than just the code within that program.
Any program that runs in a multi-process OS is under the control of the OS's scheduler, and the scheduler does ...
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 ...
18
votes
How does sleeping a thread work?
As Doc Brown mentioned in a comment, interrupts are the key, and not just for sleeping.
An interrupt is a hardware signal that the processor should stop what it's doing and run a piece of code. ...
18
votes
Why is there a shift towards asynchronous and event driven programming?
The "async" approach better facilitates human reasoning.
When most people drive, they don't need to concern themselves with how every element of the car is interacting. Forget the tires - ...
16
votes
What are the drawbacks of making a multi-threaded JavaScript runtime implementation?
A decade or so ago Brendan Eich (the inventor of JavaScript) wrote an essay called Threads Suck, which is definitely one of the few canonical documents of JavaScript's design mythology.
Whether it is ...
16
votes
What are the drawbacks of making a multi-threaded JavaScript runtime implementation?
Just guessing here to demonstrate a problem in your approach. I can't test it against the real implementation as there is no link anywhere...
I'd say it is because invariants are not always expressed ...
16
votes
Accepted
Alternative to Actor model
Three paradigms in common use are actors (e.g. Akka), Software Transactional Memory (e.g. Clojure) or traditional manual lock-wrangling. They all have their own challenges.
Traditional lock-based ...
16
votes
Accepted
How could thread safety be provided by a programming language similar to the way memory safety is provided by Java and C#?
Races occur when you have simultaneous aliasing of an object and, at least, one of the aliases is mutating.
So, to prevent races, you need to make one or more of these conditions untrue.
Various ...
14
votes
Accepted
Why is threading platform-dependent?
The book you are reading was published in 2007. The C++ API for managing threads wasn't standardised until 2011. At the time, on different systems you had to use entirely different platform-specific ...
14
votes
Accepted
How do you test and demonstrate that you have properly prevented a race condition?
Sometimes you have some control over the timing, and you can intentionally force a race in a test. When you are using a guarantee of an external system like a database, you usually can't control the ...
13
votes
Why is dealing with multiple threads considered difficult?
Concurrent programming is difficult, notably because you need to deal with synchronization issues.
All I know is that to deal with threads you have to lock all shared data till each thread finishes ...
13
votes
Accepted
Is it okay to start a thread from within a constructor of a class
Initializing the object completely in the constructor is usually preferable because it reduces the number of states, and thus making your object easier to reason about. No start and stop methods ...
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
multithreading × 675java × 120
concurrency × 101
c# × 87
c++ × 76
design × 52
c × 39
design-patterns × 29
architecture × 29
.net × 28
performance × 25
python × 24
locks × 22
synchronization × 20
asynchronous-programming × 20
operating-systems × 19
parallelism × 19
cpu × 17
multiprocessing × 16
c++11 × 15
async × 15
parallel-programming × 14
multi-core × 14
linux × 13
algorithms × 12