Nust College of Eme Nismah Saleem
Nust College of Eme Nismah Saleem
Nust College of Eme Nismah Saleem
Threading in C++
April 16, 2015
Abstract
The purpose of this assignment was to make us familiar with the concept of threading in c++. We were asked to write a program in c++
and demonstrate the concept of threading in it. We had to write the
same program then without using threads to see the difference between
the outputs of the two pieces of codes.
Introduction
Explaining Multithreading
Advantages of Threading
Some advantages include:If a thread gets a lot of cache misses, the other
thread(s) can continue, taking advantage of the unused computing resources, which thus can lead to faster overall execution, as these resources
would have been idle if only a single thread was executed. If a thread
cannot use all the computing resources of the CPU (because instructions
depend on each others result), running another thread can avoid leaving
these idle. If several threads work on the same set of data, they can actually share their cache, leading to better cache usage or synchronization
on its values. High unused computing resources
Disadvantages
An opaque attribute object that may be used to set thread attributes. You can specify a thread attribut
A single argument that may be passed to startr outine.Itmustbepassedbyref erenceasapointerc
The mileage thus varies; Intel claims up to 30 percent improvement with its HyperThreading technology,[1] while a synthetic program just performing a loop
of non-optimized dependent floating-point operations actually gains a 100 percent speed improvement when run in parallel. On the other hand, hand-tuned
assembly language programs using MMX or Altivec extensions and performing data pre-fetches (as a good video encoder might), do not suffer from cache
misses or idle computing resources. Such programs therefore do not benefit
from hardware multithreading and can indeed see degraded performance due to
contention for shared resources.
Hardware techniques used to support multithreading often parallel the software techniques used for computer multitasking of computer programs.
Thread scheduling is also a major problem in multithreading.
Implementation
A major area of research is the thread scheduler which must quickly choose
among the list of ready-to-run threads to execute next as well as maintain the
ready-to-run and stalled thread lists. An important sub-topic is the different
thread priority schemes that can be used by the scheduler. The thread scheduler might be implemented totally in software, totally in hardware, or as a
hardware/software combination.
Another area of research is what type of events should cause a thread switch
- cache misses, inter-thread communication, DMA completion, etc.
If the multithreading scheme replicates all software visible state, include
privileged control registers, TLBs, etc., then it enables virtual machines to be
created for each thread. This allows each thread to run its own operating system
on the same processor. On the other hand, if only user-mode state is saved, less
hardware is required which would allow for more threads to be active at one
time for the same die-area/cost.
Creating Threads