Lecture Notes for Client-Server Interfaces

13 March 2001 - Thread-Based Concurrency


  1. threads - the other concurrency

  2. the basics

    1. threads and processes - lightweight

    2. dynamic and cheap creation

    3. cheap synchronization

    4. concurrent execution - where's the scheduler

    5. pre-emption - both intra- and inter-process

    6. address spaces - shared global, private stack

    7. other process resources shared - memory, locks, files

    8. threads don't own resources usually, its process does.

  3. the good

    1. cheap - thread operations are fast and resource light

    2. simple sharing - global sharing is automatic; restricted sharing requires work

  4. the bad

    1. no protection - global sharing, remember

    2. thread safety - system calls

      1. gethostbyname(), gethostbyaddr(), gethostent() - use static storage

      2. gethostbyname_r(), gethostbyaddr_r(), gethostent_r() - use thread-supplied buffers

    3. support may be iffy - debugging, performance

  5. the issues

    1. resource ownership - thread allocated resources belong to the host process

    2. is the os thread aware - what do blocking calls block

  6. the posix interface

    1. management

      1. pthread_create(tid, attrs, fun, arg) - create a new thread

      2. pthread_join(tid, status) - wait for thread to terminate

      3. pthread_detach(tid) - no parent rendesvous

      4. pthread_exit(status) - self-termination

      5. pthread_cancel(tid) - terminate a thread

    2. synchronization

      1. mutexes - binary semaphores, mutual exclusion

        1. pthread_mutex_init(mutex, attrs) - create mutex semaphore

        2. pthread_mutex_destroy(mutex) - delete a mutex

        3. pthread_mutex_lock(mutex) - lock the mutex; block if locked

        4. pthread_mutex_trylock(mutex) - lock the mutex; fail if locked

        5. pthread_mutex_unlock(mutex) - unlock the mutex

      2. condition variables - coordination

        1. pthread_cond_init(cond, attrs) - create a condition variable

        2. pthread_cond_destroy(cond) - delete a condition variable

        3. pthread_cond_wait(cond, mutex) - unlock the mutex and wait; timed version too

        4. pthread_cond_signal(cond) - send a signal to a thread waiting on cond

        5. pthread_cond_broadcast(cond) - send a signal to all threads waiting on cond

    3. miscellaneous

      1. scheduling - contention scope, policy

      2. signals - signal masks

      3. attributes - threads, mutex

      4. termination functions - threads


This page last modified on 14 March 2001.