Multi-threading related questions including technique, structure, and safety issues.
Questions tagged [multithreading]
680 questions
81
votes
4 answers
What is a thread pool?
How would one implement a threadpool? I've been reading on wikipedia for "threadpool" but I still can't figure out what one should do to solve this question (possibly because I didn't quite understand what a threadpool is in simple terms).
Can…
John Smith
- 1,729
- 2
- 17
- 20
60
votes
15 answers
How important is multithreading in the current software industry?
I have close to 3 years experience writing web applications in Java using MVC frameworks (like struts). I have never written multithreaded code till now though I have written code for major retail chains.
I get a few questions on multithreading…
user2434
- 1,277
23
votes
6 answers
Multithreading: am I doing it wrong?
I'm working on an application that plays music.
During playback, often things need to happen on separate threads because they need to happen simultaneously. For example, the notes of a chord need to be heard together, so each one is assigned its own…
Aviv Cohn
- 21,388
20
votes
8 answers
What causes unpredictability when doing multi threading
Multi threading could cause a racing condition if two threads are accessing the same memory slot, but why is that? From a HW point of view, if the two cores are designed the same, internal pipelines are the same, the logic gates/transistors pass…
Dan
- 319
18
votes
7 answers
Can you explain why multiple threads need locks on a single-core CPU?
Assume these threads run in single core cpu. As a cpu only run one instruction in one cycle. That is said, even thought they share the cpu resource. but the computer ensure that one time one instruction. So is the lock un-necessary for…
pythonee
- 339
12
votes
7 answers
What false ideas are there that puts people off using threads?
Implementing threading in a program is hard, yes, however why is it that some people will not implement them even when there is an obvious need for it.
An example: Program has to load a dataset from a database, the thing to do would be to make the…
Tony The Lion
- 395
11
votes
2 answers
What is a "lock ordering inversion"?
I am looking into Eric Lippert's answer to this Stack Overflow question.
In his answer, he uses the phrase "lock ordering inversions" in regard to deadlocks. I've searched the web and have come across priority inversion. Is this the same concept? If…
fractor
- 221
10
votes
6 answers
If I use locks, can my algorithm still be lock-free?
A common definition of lock-free is that at least one process makes progress. 1
If I have a simple data structure such as a queue, protected by a lock, then one process can always make progress, as one process can acquire the lock, do what it wants,…
Joe Pension
- 101
- 1
- 3
10
votes
1 answer
THREADS: Kernel threads vs. Kernel-supported threads vs. User-level threads?
Does anyone know what the difference between these are?
It seems to me that kernel threads correspond to the code that runs the kernel (intuitively), but I'm not sure about the other two...
Also, would the pthreads standard be considered user-level…
Dark Templar
- 6,303
- 16
- 47
- 47
6
votes
2 answers
Preemptive scheduling with "do not disturb"
In this answer about threading it is said:
In preemptive scheduling, a thread can be interrupted at any time, either by a timer interrupt or any other interrupt or during a system call. The part of the system that performs the context switch must…
user395579
6
votes
1 answer
Threading models when talking to hardware devices
When writing an interface to hardware over a communication bus, communications timing can sometimes be critical to the operation of a device.
As such, it is common for developers to spin up new threads to handle communications.
It can also be a…
Fuzz
- 385
5
votes
3 answers
What are the so-called "levels" of understanding multithreading?
I seem to remember reading somewhere some list of 4 "levels" of understanding multithreading. This may have been in a formal publication, or it may have been in an extremely informal context (even like in a Stack Overflow question, for example).…
Dan Tao
- 1,201
4
votes
3 answers
N threads enter, one and only one should do extra processing that others wait for
My task is, I think, pretty interesting, if a bit unusual. Any number of threads can call function f(). They add some data to a buffer and begin waiting (the function is blocking). Eventually some extra processing has to be done on the whole buffer,…
Violet Giraffe
- 284
4
votes
3 answers
How to preserve order of incoming requests on a multithreaded server
I want to write a multithreaded server application which is able to process requests in a multithreaded fashion while keeping up execution order of incoming requests of the same client.
For example if client A sends a message M1 and then a message…
AlexLiesenfeld
- 141
4
votes
1 answer
Producer-consumer pattern with consumer restrictions
I have a processing problem that I am thinking is a classic producer-consumer problem with the two added wrinkles that there may be a variable number of producers and there is the restriction that no more than one item per producer may be consumed…
Dan
- 243