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

Books

More information:

Related tags

139166 questions
34
votes
7 answers

How to demonstrate java multithreading visibility problems?

If variables in Java are accessed from multiple threads, one must ensure that they are safely published. This usually means using synchronizedor volatile. I have got the impression, that some of my colleagues do not take this issue seriously, since…
Joe23
  • 5,683
  • 3
  • 25
  • 23
34
votes
3 answers

How does a single servlet handle multiple requests from client side

How does a single servlet handle multiple client requests coming in the form of user requests ? Based on the singleton design pattern I know we get a single instance of servlet created , but how does a single servlet handle millions of requests .…
shivam-shekhar
  • 457
  • 1
  • 4
  • 9
34
votes
3 answers

Application threads vs Service threads

What are the advantages/disadvantages in placing a lengthy network access code in a thread in an activity or a thread in a service? How would it affect the application? I am writing a streaming audio player and from what I've read so far putting…
zerayaqob
  • 426
  • 1
  • 6
  • 12
34
votes
3 answers

What is StampedLock in Java?

I am working on a Java code, I need to implement threading in it. I was going through JAVA 8 API and I come to know about Stamped Locks. Can anyone tell me why to use StampedLocks in multithreading?
Mohit
  • 1,185
  • 2
  • 11
  • 25
34
votes
4 answers

Why is Parallel.ForEach much faster then AsParallel().ForAll() even though MSDN suggests otherwise?

I've been doing some investigation to see how we can create a multithreaded application that runs through a tree. To find how this can be implemented in the best way I've created a test application that runs through my C:\ disk and opens all…
Devedse
  • 1,801
  • 1
  • 19
  • 33
34
votes
3 answers

std::thread error (thread not member of std)

I compiled & installed gcc4.4 using macports. When I try to compile using -> g++ -g -Wall -ansi -pthread -std=c++0x main.cpp...: #include ... std::thread t(handle); t.join(); .... The compiler returns: cserver.cpp: In member…
luis
  • 345
  • 1
  • 3
  • 4
34
votes
1 answer

Spring async method called from another async method

I'm using Spring 4 and I've noticed an odd behaviour... if I'm calling an async method multiple times from a normal instance method then they are all called in different threads and finish at random times. But if I call multiple times an async…
spauny
  • 4,976
  • 9
  • 44
  • 61
34
votes
2 answers

Thread.VolatileRead() vs Volatile.Read()

We are told to prefer Volatile.Read over Thread.VolatileRead in most cases due to the latter emitting a full-fence, and the former emitting only the relevant half-fence (e.g. acquire fence); which is more efficient. However, in my understanding,…
Xenoprimate
  • 7,691
  • 15
  • 58
  • 95
34
votes
7 answers

What kind of behaviour causes an interrupted exception?

I'm relatively new to Threading in Java and I've noticed that everytime I use Thread.sleep() I have to catch InterrupetdException. What kind of behaviour causes this, and in simple applications where I have a monitor thread can I just Ignore the…
Omar Kooheji
  • 54,530
  • 68
  • 182
  • 238
34
votes
2 answers

Is localStorage thread safe?

I'm curious about the possibility of damaging localStorage entry by overwriting it in two browser tabs simultaneously. Should I create a mutex for local storage? I was already thinking of such pseudo-class: LocalStorageMan.prototype.v =…
Tomáš Zato
  • 50,171
  • 52
  • 268
  • 778
34
votes
5 answers

Atomic properties vs thread-safe in Objective-C

In most of the discussions I've read, it indicates that making a property atomic does not guarantee it to be thread-safe, it just guarantees that the value returned won't be garbage as a result of one object writing to it and another trying to read…
Doug Smith
  • 29,668
  • 57
  • 204
  • 388
34
votes
1 answer

Redirecting stdout and stderr to a PyQt4 QTextEdit from a secondary thread

Stack overflow. Once again, I come to you in a time of dire need, teetering precariously on the brink of insanity. This question - as may be evident from the title - is an amalgamation of several other questions I have seen answered here. I have a…
araisbec
  • 1,223
  • 3
  • 16
  • 27
34
votes
2 answers

std::thread pass by reference calls copy constructor

Well I have an issue with passing data into a thread using std::thread. I thought I understood the general semantics of copy constructors, etc. but it seems I don't quite grasp the problem. I have a simple class called Log that has hidden it's copy…
xaviersjs
  • 1,579
  • 1
  • 15
  • 25
34
votes
6 answers

Best practice to handle orientation change: Android

I was going through various practices to handle orientation change with threads and AsyncTask. I came across following solutions: Attach-detach model : Attaching and detaching activity to threads and AsyncTask while preserving their instance.…
Gaurav Arora
  • 17,124
  • 5
  • 33
  • 44
34
votes
8 answers

Asynchronous Delegates Vs Thread/ThreadPool?

I need to execute 3 parallel tasks and after completion of each task they should call the same function which prints out the results. I don't understand in .net why we have Asychronous calling (delegate.BeginInvoke() & delegate.EndInvoke()) as well…
claws
  • 52,236
  • 58
  • 146
  • 195