Simon
Simon

Reputation: 2115

Random error on mutex lock

A mutex lock succeeds or fails randomly, and fails with either :

Invalid argument

or

tpp.c:62: __pthread_tpp_change_priority: Assertion `new_prio == -1 || (new_prio >= __sched_fifo_min_prio && new_prio <= __sched_fifo_max_prio)' failed.

The code is very basic as you can see here :

pthread_mutex_t mutex;
main() {
  int ret;
  pthread_mutexattr_t attr;
  pthread_mutexattr_setpshared(&attr, PTHREAD_PROCESS_SHARED);
  ret = pthread_mutex_init(&mutex, &attr);
  if (ret != 0) {
    printf("pthread_mutex_init\n");
    return 1;
  }
  ret = pthread_mutex_lock(&mutex);
  if (ret != 0) {
    printf("mutex_lock failed %s\n", strerror(ret));
    return 1;
  }
  ret = pthread_mutex_unlock(&mutex);
  if (ret != 0) {
    printf("mutex_unlock failed %s\n", strerror(ret));
    return -1;
  }

Why is that ?

Upvotes: 2

Views: 1037

Answers (1)

Andrew Henle
Andrew Henle

Reputation: 1

You're not initializing attr. Its contents are undefined.

See pthread_mutexattr_init:

DESCRIPTION

The function pthread_mutexattr_init() initialises a mutex attributes object attr with the default value for all of the attributes defined by the implementation.

Upvotes: 6

Related Questions