Information Technology Reference
In-Depth Information
Thread 1
Thread 2
Thread 3
Thread 1
Thread 2
Thread 3
a) One execution
b) Another execution
Thread 1
Thread 2
Thread 3
c) Another execution
Figure4.4: A handful of the many possible ways that three threads might
be interleaved at runtime. Threads runs at unpredictable speeds due to many
factors including policy decisions by the scheduler, the number of available
processors, the physical characteristics of the processors, other programs com-
peting for resources, and the arrival of I/O events.
ative speeds of execution, multi-threaded programs use explicit synchronization
to control how threads interact with one another.
The physical reality is that the relative execution speeds of different threads
are significantly affected by many factors outside their control. For example,
on a modern processor, accessing memory can stall a processor for hundreds or
thousands of cycles if there is a cache miss. Other factors include how frequently
the scheduler preempts the thread, how many physical processors are present on
a machine, how large the caches are, how fast the memory is, how the energy-
saving rmware adjusts the processors' clock speeds, what network messages
arrive, or what input is received from the user. As a result, execution speeds
for the different threads of a program are hard to predict, can vary on different
hardware, and can even vary from run to run on the same hardware.
4.2
Simple API and example
Figure 4.5 shows our simple thread API called sthreads (\simple threads.")
Sthreads is based on the Posix standard pthreads API, but it simplifies things by
omitting some options and error handling. Although the sthreads API is based
 
Search WWH ::




Custom Search