POSIX Threads - PowerPoint PPT Presentation

1 / 6
About This Presentation
Title:

POSIX Threads

Description:

POSIX Threads. Compiling. Include pthread.h. Solaris. cc mt ... - lpthread. Linux. gcc pthread ... Do not manually define _REENTRANT, or link against any ... – PowerPoint PPT presentation

Number of Views:158
Avg rating:3.0/5.0
Slides: 7
Provided by: kennet139
Category:
Tags: posix | posix | threads

less

Transcript and Presenter's Notes

Title: POSIX Threads


1
POSIX Threads
2
Compiling
  • Include pthread.h
  • Solaris
  • cc mt -lpthread
  • Linux
  • gcc pthread
  • Do not manually define _REENTRANT, or link
    against any libraries.

3
Creation
  • int pthread_create(pthread_t thread, const
    pthread_attr_t attr, void (start_routine)(void
    ), void arg)
  • Example
  • extern "C" void run(void )
  • int ec pthread_create(tid, NULL, run, NULL)
  • Passing data
  • int data
  • ec pthread_create(tid, NULL, run, data)

4
Attributes
  • int pthread_attr_init(pthread_attr_t attr)
  • int pthread_attr_setdetachstate(pthread_attr_t
    attr, int detachstate)
  • PTHREAD_CREATE_DETACHED
  • PTHREAD_CREATE_JOINABLE
  • int pthread_attr_setscope(pthread_attr_t attr,
    int scope)
  • PTHREAD_SCOPE_SYSTEM
  • PTHREAD_SCOPE_PROCESS

5
Mutexes
  • int pthread_mutex_init(pthread_mutex_t mutex,
    const pthread_mutexattr_t mutexattr)
  • ?
  • pthread_mutex_t lock
  • void f()
  • pthread_mutex_lock(lock)
  • pthread_mutex_unlock(lock)
  • void g()
  • pthread_mutex_lock(lock)
  • f()
  • pthread_mutex_unlock(lock)
  • Attributes
  • pthread_mutexattr_init
  • __linux
  • __sun

6
Condition Variables
  • int pthread_cond_init(pthread_cond_t cond,
    pthread_condattr_t cond_attr)
  • pthread_cond_signal
  • Awakens one waiter.
  • pthread_cond_broadcast
  • Awakens all waiters.
  • pthread_cond_wait
  • Atomically releases mutex and blocks. Avoids
    missed signals.
Write a Comment
User Comments (0)
About PowerShow.com