Questions tagged [multithreading]

For questions regarding multi-threading, the ability of a computer or a program to perform work concurrently or asynchronously by utilizing multiple concurrent streams of execution (generally referred to as threads).

Multi-threading is a common model to implement SM in multi-cored machines, where threads share memory through shared variables. In this model in parallel programming a processor can create multiple threads that will be executed in parallel. Each thread has its own stack, variables and ID, considered private state. For every thread there is a unique heap shared by all, then considered shared memory.

In order to allow a volume of work to be most effectively and safely divided into multiple concurrent streams of execution, a number of critical areas need to be addressed.

  • Scheduling: ensure worker tasks are able to progress independently and effectively (e.g. deadlock/livelock avoidance)
  • Publication: ensure data altered in one thread is only visible to others as expected
  • Synchronization: ensure critical regions are protected from multiple concurrent updates causing data loss/corruption.

The underlying tenet of concurrent processing is Amdahl's law (graph). This law governs the diminishing amount of throughput that can be achieved by greater numbers of concurrent processors/cores. Therefore the overall aim of multi-threading is to minimize the amount of serial execution (exclusive locking) within any concurrent system.

Frequently Asked Questions


More information:

Related tags

139166 questions
42 answers

"implements Runnable" vs "extends Thread" in Java

From what time I've spent with threads in Java, I've found these two ways to write threads: With implements Runnable: public class MyRunnable implements Runnable { public void run() { //Code } } //Started with a "new Thread(new…
  • 24,139
  • 4
  • 19
  • 7
8 answers

C++11 introduced a standardized memory model. What does it mean? And how is it going to affect C++ programming?

C++11 introduced a standardized memory model, but what exactly does that mean? And how is it going to affect C++ programming? This article (by Gavin Clarke who quotes Herb Sutter) says that, The memory model means that C++ code now has a…
  • 353,942
  • 115
  • 666
  • 851
35 answers

What is the difference between a process and a thread?

What is the technical difference between a process and a thread? I get the feeling a word like 'process' is overused and there are also hardware and software threads. How about light-weight processes in languages like Erlang? Is there a definitive…
James Fassett
  • 40,306
  • 11
  • 38
  • 43
47 answers

How do I update the GUI from another thread?

Which is the simplest way to update a Label from another Thread? I have a Form running on thread1, and from that I'm starting another thread (thread2). While thread2 is processing some files I would like to update a Label on the Form with the…
  • 18,196
  • 16
  • 40
  • 58
24 answers

How do I use threading in Python?

I would like a clear example showing tasks being divided across multiple threads.
  • 14,955
  • 3
  • 18
  • 6
33 answers

Difference between "wait()" vs "sleep()" in Java

What is the difference between a wait() and sleep() in Threads? Is my understanding that a wait()-ing Thread is still in running mode and uses CPU cycles but a sleep()-ing does not consume any CPU cycles correct? Why do we have both wait() and…
  • 23,089
  • 20
  • 71
  • 85
18 answers

What is a race condition?

When writing multithreaded applications, one of the most common problems experienced is race conditions. My questions to the community are: What is the race condition? How do you detect them? How do you handle them? Finally, how do you prevent them…
  • 29,564
  • 11
  • 33
  • 24
8 answers

How do servlets work? Instantiation, sessions, shared variables and multithreading

Suppose, I have a webserver which holds numerous servlets. For information passing among those servlets I am setting session and instance variables. Now, if 2 or more users send request to this server then what happens to the session variables? Will…
Ku Jon
  • 12,503
  • 3
  • 16
  • 4
34 answers

Android "Only the original thread that created a view hierarchy can touch its views."

I've built a simple music player in Android. The view for each song contains a SeekBar, implemented like this: public class Song extends Activity implements OnClickListener,Runnable { private SeekBar progress; private MediaPlayer mp; …
  • 15,819
  • 12
  • 42
  • 45
17 answers

What does 'synchronized' mean?

I have some questions regarding the usage and significance of the synchronized keyword. What is the significance of the synchronized keyword? When should methods be synchronized? What does it mean programmatically and logically?
  • 27,036
  • 42
  • 89
  • 117
12 answers

Multiprocessing vs Threading Python

I am trying to understand the advantages of multiprocessing over threading. I know that multiprocessing gets around the Global Interpreter Lock, but what other advantages are there, and can threading not do the same thing?
  • 10,989
  • 4
  • 19
  • 7
31 answers

Is there any way to kill a Thread?

Is it possible to terminate a running thread without setting/checking any flags/semaphores/etc.?
Sudden Def
  • 10,031
  • 3
  • 18
  • 8
26 answers

When and how should I use a ThreadLocal variable?

When should I use a ThreadLocal variable? How is it used?
5 answers

What is thread safe or non-thread safe in PHP?

I saw different binaries for PHP, like non-thread or thread safe? What does this mean? What is the difference between these packages?
  • 10,925
  • 5
  • 20
  • 8
10 answers

What is a mutex?

A mutex is a programming concept that is frequently used to solve multi-threading problems. My question to the community: What is a mutex and how do you use it?
  • 29,564
  • 11
  • 33
  • 24
2 3
99 100