Operating Systems Lecture Notes

2014 September 11 • Threads


Outline

Executing Programs

Threads

The Thread Abstraction

Threads and Processes

Thread Resources

Single- and Multi-Threading

single- and multi-threading

Thread Descriptors

Process Resources

Sharing Example

Thread Management

Thread Create and Delete

Fork-Join Example

fork-exit-join example

Java Threads

The Thread-Process Split

Some Process Code

switch pid = fork()

  case 0
    execve("null-process")

  case -1
    // fork() failed

  default
    const pid_t p = wait()
    if (p == -1)
      // wait() failed

    if (p != pid)
      // unexpected pid from wait() 

Some Thread Code

s = pthread_create(&tid, NULL, null_thread, NULL);
if (s != 0)
  // pthread_create() failed

s = pthread_join(tid, NULL)
if (s != 0)
  // pthread_join() failed

void * null_thread(void *)
  pthread_exit(NULL)

Some Data

Implementing Threads

Threads Outside the OS

User-Space Threads

OS-Based Threads

User and Kernel Threads

One-to-One Mappings

Many-to-One Mappings

Many-to-Many Mappings

Summary

References


This page last modified on 2012 February 6.

Creative
    Commons License