Forum Discussion

Altera_Forum's avatar
Altera_Forum
Icon for Honored Contributor rankHonored Contributor
19 years ago

pthread mutex, cond

1)

This code does not run properly : lock is always possible

pthread_mutex_t m_mutex;

pthread_mutex_init(&m_mutex, NULL)

pthread_mutex_lock(&m_mutex)

This code works fine:

pthread_mutex_t m_mutex;

pthread_mutexattr_t m_attr;

pthread_mutexattr_init(&m_attr);

pthread_mutex_init(&m_mutex, &m_attr);

pthread_mutex_lock(&m_mutex);

What is the problem?

2)

This code does not run properly:

pthread_cond_t m_thread_flag_cv;

pthread_condattr_t m_attr;

pthread_condattr_init(&m_attr);

pthread_cond_init (&m_thread_flag_cv, &m_attr);

This code works fine:

pthread_cond_t m_thread_flag_cv;

pthread_condattr_t m_attr;

pthread_condattr_init(&m_attr);

pthread_condattr_setpshared(&m_attr, PTHREAD_PROCESS_PRIVATE);

pthread_cond_init (&m_thread_flag_cv, &m_attr);

Normally pthread_condattr_setpshared() is not needed because pthread_condattr_init() must set it.

What is the problem?

krgo
No RepliesBe the first to reply