Threading issues
tpp.c:63: __pthread_tpp_change_priority: Assertion is a known problem and solved:
https://sourceware.org/ml/libc-help/2008-05/msg00071.html
in brief, the problem is caused by repeated locking of a fast mutex
, and solved by using a recursive mutex
, and the default pthread_mutex_t
is not recursive. Is it possible that there's pthread_mutex_t
deeply inside the thread running code ??
BTW, to make the mutex recursive, plz set the mutex attribute with attribute PTHREAD_MUTEX_RECURSIVE_NP
.
Here is your program cleaned up. It runs without the above assertion:
#include <stdio.h>
#include <stdlib.h>
#include <pthread.h>
#include <string.h>
static pthread_t th[5];
void *
tfunc (void *ptr)
{
sleep (5); /* remove this to test it without the sleep */
pthread_exit (NULL);
}
void
test ()
{
int i;
memset (th, 0, 5 * sizeof (pthread_t));
for (i = 0; i < 5; i++)
{
if (pthread_create (&th[i], NULL, tfunc, NULL) < 0)
perror ("pthread_create");
}
for (i = 0; i < 5; i++)
{
if (pthread_join (th[i], NULL) < 0)
perror ("pthread_join");
}
}
int
main (int argc, char **argv)
{
while (1)
{
test ();
}
exit (0);
}
Here's what I noticed when cleaning it up:
for( i = 0; i < 5, i++ )
comma not semicolon means loop may not have been workingin
test()
,th
was not zeroed meaning any failedpthread_create
was using an old thread reference.In
tfunc
, you did apthread_join
if( g_count == value_needed )
, but then you exited anyway, i.e. you were always immediately doing thepthread_join
or the equivalent. Note I also tested the version below without thesleep()
, so exiting immediately now works.various other orthographic issues.
no error handling
As there were a few compilation problems, I suspect that you may not have compiled the code you pasted above, but something more complicated. And I suspect it's part of that that's causing the issue.
If you post a minimal example of compilable code that actually causes the issue, I might be able to help you further.