[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[Libevent-users] Error in evthread_pthread.c



Hello.

My application had a very confusing crash today, it failed at assertion deep inside pthreads library. Here is an exact output:


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


After a bit of googling around I found a good reference to the same problem: http://sourceware.org/ml/libc-help/2008-05/msg00072.html and, after checking libevent code, it is true, pthread_mutexattr_init() call is missing. In evthread_pthread.c we have a static mutex attribute at line 42. It is used to initialize all recursive locks, for example locks in bufferevents. But it is zero-initialized according to static variable initialization rules. It is wrong for some (all?) POSIX platforms, for example we have this code in glibc:


int
__pthread_mutexattr_init (attr)
     pthread_mutexattr_t *attr;
{
  if (sizeof (struct pthread_mutexattr) != sizeof (pthread_mutexattr_t))
    memset (attr, '\0', sizeof (*attr));

  /* We use bit 31 to signal whether the mutex is going to be
     process-shared or not.  By default it is zero, i.e., the mutex is
     not process-shared.  */
  ((struct pthread_mutexattr *) attr)->mutexkind = PTHREAD_MUTEX_NORMAL;

  return 0;
}
strong_alias (__pthread_mutexattr_init, pthread_mutexattr_init)


You can easily see that it is not the same as zero-initialization, so it must be fixed. Probably we can use pthread_once to do one-time initialization at first request.

P.S. Can someone take a look at issue 18 in libevent github repo? It is also related to bufferevents and crashed my application a couple of times.

Thanks in advance.
***********************************************************************
To unsubscribe, send an e-mail to majordomo@xxxxxxxxxxxxx with
unsubscribe libevent-users    in the body.