Skip to main content
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 ...
Philip Kendall's user avatar
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 ...
Iron Gremlin's user avatar
  • 1,115
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 ...
Martin Maat's user avatar
  • 18.6k
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.
Jörg W Mittag's user avatar
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 ...
Kilian Foth's user avatar
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 ...
pjc50's user avatar
  • 15.3k
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 ...
Jörg W Mittag's user avatar
24 votes
Accepted

Writing public libraries: Should I let the consumer of the library enforce thread safety?

You should make your library thread-safe, but that does not mean that you should be sprinkling synchronization primitives around your code base. For the average library, which is not explicitly ...
Bart van Ingen Schenau's user avatar
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 ...
Vilx-'s user avatar
  • 5,440
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 ...
Caleth's user avatar
  • 12.4k
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 - ...
TheRubberDuck's user avatar
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 ...
Kilian Foth's user avatar
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 ...
Alex's user avatar
  • 3,952
16 votes

Can multi-threading improve performance of an IO-bound process?

I/O performance has two aspects that you must distinguish: latency and throughput. One measures how long you have to wait for the first byte of a response, the other how long you have to wait ...
Kilian Foth's user avatar
15 votes
Accepted

Unit test which asserts that current thread is the main thread

Let me show you my favorite unit test principles: A test is not a unit test if: It talks to the database It communicates across the network It touches the file system It can't run at ...
candied_orange's user avatar
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 ...
Karl Bielefeldt's user avatar
14 votes
Accepted

Can functional programming languages have deadlock conditions?

The quote is correct in principle. If you don't have any mutable state or side effects then you don't need to lock anything and without locks you don't get deadlocks. But in reality, most programs, ...
JacquesB's user avatar
  • 62.3k
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 ...
amon's user avatar
  • 136k
13 votes

How could thread safety be provided by a programming language similar to the way memory safety is provided by Java and C#?

Java and C# provide memory safety by checking array bounds and pointer dereferences. It's important to first think about how C# and Java do this. They do so by converting what is undefined behaviour ...
Eric Lippert's user avatar
  • 46.6k
13 votes
Accepted

If the whole point of recursion is to break the problem into multiple smaller problems, what if those problems were solved in parallel?

Recursion isn't really about breaking problems into smaller ones or enabling concurrency; it's about solving self-similar problems. Consider this representation of a Binary Search Tree: public class ...
Robert Harvey's user avatar
13 votes
Accepted

Implementing a hash table with true concurrency

I have wrestled with this. I did a few iterations on my design... First solution: Just have a hash table with a global lock. Second solution: Wait free fixed size hash table. We need to figure out ...
Theraot's user avatar
  • 9,261
12 votes
Accepted

Immediately awaiting an asynchronous call

I think you misunderstand the await call. What async and await do is allow the thread you are executing on (not just the main thread) to continue working. The mechanism that supports this is called ...
JimmyJames's user avatar
  • 30.9k
12 votes

Is the meaning of `const` still thread-safe in C++11?

The video you cited is for an advanced and expert audience. Herb Sutter tries to bring this audience to a consensus on how to best communicate the intent of these keywords to other people, in this age ...
rwong's user avatar
  • 17.2k
12 votes

Does it ever make sense to use more concurrent processes than processor cores?

In A.I. it is common for people to observe super-linear speedups when they write parallel algorithms (that is, > K times speedup with K processes running on K cores). This is because you are often ...
Chris Jefferson's user avatar
11 votes

Why is multithreading not used everywhere?

I want to emphasize a point you made that multithreading is hard to implement. Some problems are naturally broken into independent parts that are easily parallelizable ("embarrassingly parallel&...
qwr's user avatar
  • 332
11 votes

Does it ever make sense to use more concurrent processes than processor cores?

You can take the example of compiled Linux distributions (like Gentoo): to optimize the compilation time, it is obviously using parallel compilation using more processes than the number of available &...
Philippe Verdy's user avatar
11 votes

Why do modern operating systems *ever* have perceptible input (keyboard/mouse) lag?

In my experience, on most computers I have ever used, this is usually caused by inappropriate swapping to disk. Every other cause (such as operating system locks) is significantly less common. When ...
Stack Exchange Broke The Law's user avatar
11 votes
Accepted

How can a web browser simultaneously run more videos than the number of CPU cores?

is each window running a separate thread, where the threads are switching quicker than I can differentiate them? Yep, pretty much this. If you look at task manager or other tool you will see ...
LoztInSpace's user avatar
  • 1,348
11 votes
Accepted

What problem does Rust's "atomic reference count" actually solve?

The problem is there is an assumption violation in the sequence of events: object has ref-cnt 1 This implies that object is only visible from 1 Arc reference. In rust this also implies that there are ...
user1937198's user avatar

Only top scored, non community-wiki answers of a minimum length are eligible