Questions tagged [multithreading]

Multi-threading related questions including technique, structure, and safety issues.

671 questions
137
votes
3 answers

Why Was Python Written with the GIL?

The global interpreter lock (GIL) seems to be often cited as a major reason why threading and the like is a touch tricky in Python - which raises the question "Why was that done in the first place?" Being Not A Programmer, I've got no clue why that…
Fomite
  • 2,616
  • 6
  • 18
  • 20
103
votes
13 answers

What can multiple threads do that a single thread cannot?

While threads can speed up execution of code, are they actually needed? Can every piece of code be done using a single thread or is there something that exists that can only be accomplished by using multiple threads?
AngryBird
  • 1,805
  • 5
  • 17
  • 22
80
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,719
  • 2
  • 17
  • 20
78
votes
1 answer

Is there a difference between fibers, coroutines and green threads and if that is so what is it?

Today I was reading several articles on the Internet about fibers, coroutines and green threads, and it seems like these concepts have very much in common, but there are slight differences, especially when we talk about fibers and coroutines. Is…
DejanLekic
  • 913
  • 1
  • 7
  • 8
73
votes
3 answers

How does a single thread run on multiple cores?

I am trying to understand, at a high-level, how single threads run across multiple cores. Below is my best understanding. I do not believe it is correct though. Based on my reading of Hyper-threading, it seems the OS organizes the instructions of…
Evorlor
  • 1,440
  • 2
  • 16
  • 22
69
votes
6 answers

Testing multi-threaded race conditions

Reading the comments to this answer, specifically: Just because you can't write a test doesn't mean it's not broken. Undefined behaviour which usually happens to work as expected (C and C++ are full of that), race conditions, potential reordering…
62
votes
1 answer

Are go-langs goroutine pools just green threads?

The commentator here offers the following criticism of green threads: I was initially sold on the N:M model as a means of having event driven programming without the callback hell. You can write code that looks like pain old procedural code but…
hawkeye
  • 4,819
  • 3
  • 24
  • 35
61
votes
10 answers

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

I've got some process in Go. Here's an example counting lines in text, though the question is meant to be far more general than this particular example: func lineCount(s string) int { count := 0 for _, c := range s { if c == '\n' { …
TheEnvironmentalist
  • 1,159
  • 1
  • 8
  • 14
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
  • 1
  • 12
  • 14
55
votes
12 answers

Why would a program require a specific minimum number of CPU cores?

Is it possible to write code (or complete software, rather than a piece of code) that won't work properly when run on a CPU that has less than N number of cores? Without checking it explicitly and failing on purpose: IF (noOfCores < 4) THEN don't…
uylmz
  • 1,129
  • 1
  • 8
  • 17
53
votes
16 answers

Should I take care of race conditions which almost certainly has no chance of occuring?

Let's consider something like a GUI application where main thread is updating the UI almost instantaneously, and some other thread is polling data over the network or something that is guaranteed to take 5-10 seconds to finish the job. I've received…
TtT23
  • 1,553
  • 4
  • 20
  • 28
52
votes
8 answers

What are the drawbacks of making a multi-threaded JavaScript runtime implementation?

I've been working on a multi-threaded JavaScript runtime implementation for the past week. I have a proof of concept made in C++ using JavaScriptCore and boost. The architecture is simple: when the runtime finishes evaluating the main script it…
voodooattack
  • 523
  • 1
  • 4
  • 9
50
votes
19 answers

Servicing background tasks on a large site

We're dealing with an interesting problem on StackOverflow. We've got a whole bunch of little "needs to be done soon-ish" tasks. An example is updating "Related Questions" lists. What we've done in the past is to piggy-back those tasks onto some…
Kevin Montrose
  • 775
  • 3
  • 9
  • 16
43
votes
10 answers

Why should your code not use 100% CPU?

I'm speaking specifically about a C# .NET 4 program running on Windows XP or higher, but general answers are also acceptable. Assume an already optimized and efficient program. The problem here is entirely down to effects of high CPU usage on…
Nick Udell
  • 1,214
  • 2
  • 11
  • 17
40
votes
5 answers

Does immutability entirely eliminate the need for locks in multi-processor programming?

Part 1 Clearly Immutability minimizes the need for locks in multi-processor programming, but does it eliminate that need, or are there instances where immutability alone is not enough? It seems to me that you can only defer processing and…
1
2 3
44 45