Rensselaer Polytechnic Institute

prettybadelyngeSoftware and s/w Development

Nov 18, 2013 (3 years and 6 months ago)

60 views

Rensselaer Polytechnic Institute

CSCI
-
4210


Operating Systems

David Goldschmidt, Ph.D.


A process has a single
thread of execution



Program execution

starts with
main()



Program has
sole access


to data, file descriptors,

registers, program stack,

program heap, etc.


A process has a single
thread of execution



One process creates

a new process via
fork()



Child process has its own

resources and its own

single thread of execution

fork
()


A process may create additional

threads of execution



This is
multithreading



Each thread has its own

program stack and registers


Do threads share access to

data, file descriptors, and

other operating system

resources?


A
kernel thread

is a thread of execution

used by the operating system


Thread management tasks are

performed by the operating system


Virtually all modern operating systems

support kernel threads


A
user thread

is a thread of execution in an
application or other non
-
kernel program


User threads must be tied to kernel threads



User threads are often provided via APIs:


POSIX
Pthreads

library (Unix, Mac OS X)


Win32 threads library


Java threads API (managed by each JVM)


Many
-
to
-
one


User threads are mapped to one kernel thread


Single kernel thread might

block all user threads


Support for multiple CPUs?


Many
-
to
-
many


User threads (
m
) are mapped to a group of
kernel threads (
n
)


typically with
m

>
n


Single kernel thread will

not
block all user threads


Support for multiple CPUs?


Some flavors of Unix

use this model


One
-
to
-
one


Each user thread is mapped to a kernel thread


Support for multiple CPUs?








Linux and Windows use this model, though the

number of allowed user threads is limited


The
main()

method is executed as a single
thread within the
Java Virtual Machine

(
JVM
)


Create additional threads by either:


Extending the
Thread

class


Implementing the
Runnable

interface



Thread executes via the
run()

method


But

you
start

a thread by calling
start()