Points

  • set_concurrency: control the number of thread.
  • pshared: Could share by multi process but not multi threads in one process. Need dynamic init

    Sync ways

    join

    pthread_t thread[NUM_THREADS]

pthread_join(threadid,status)

mutex

pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER

condition

pthread_cond_t mutex = PTHREAD_COND_INITIALIZER

  1. int pthread_cond_wait(pthread_cond_t *cptr, pthread_mutex_t *mptr)
  2. int pthread_cond_signal(pthread_cond_t *cptr)

Interrupt

R/W mutex and POSIX signal may not release when abnormal interruption like process exit unexpectedly.

Refer