<PREV> <INDEX> <NEXT>

Resource Sharing Mechanisms

Threads:

        pthread_t   thread;
pthread_attr_t   attr;
pthread_attr_*();
pthread_create(*thread, *attr, *start_routine, *arg);
pthread_join(thread, **thread_return);
pthread_exit(*retval);
pthread_detach(thread);

  • different: I/O, PID
  • common: memory, file handlers
  • states: joinable/detached
  • more attributes: schedpolicy, schedparam, inheritsched

Mutex (MUTual Exclusion):

        pthread_mutex_t   mutex;
pthread_mutexattr_t   attr;
pthread_mutex_init(&mutex, attr);
pthread_mutex_lock(&mutex);
pthread_mutex_trylock(&mutex);
pthread_mutex_unlock(&mutex);

  • states: locked/unlocked
  • defines thread owning the memory area
  • attributes: fast, recursive, error checking
  • the programmer must associate the mutex--memory pair

Conditionals:
  • synchronization device  -- associate with a mutex
  • type: phtread_cond_t
  • handled by: phtread_cond_*
  • wait, signal, broadcast

Semaphores:
  • sem_*
  • not based on thread ownership
  • integer values
  • not fully implemented in LinuxThreads

<PREV> <INDEX> <NEXT>