Thread problems

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

Hello everybody,

I'm trying to restart a program that creates 5 threads and after pthread_join (), I make a return based on which I re-run the whole program, that is, it is in the while (1) loop.

When I run the program a second time, I get an error message, as you can see above. I can not trace its origin. Can someone explain the reason for this error?

FYI: I do not use any locks or mutex semaphores. I wait for the threads to join, after which I started the whole program again. Does this have anything to do with race conditions? I assume that when I wait for all 5 threads to join, only then can I exit pthread

main
{
    while(1)
    {
         test();
    }
}//main

test()
{
    for( i = 0; i < 5; i++ )
        pthread_create( &th[i], NULL, tfunc, &some_struct);

    for( i = 0; i < 5, i++ )
        pthread_join( th[i], NULL);
}

void * tfunc( void * ptr )
{
    // waiting for a callback function to set a global counter to a value
    // sleep until then
    if( g_count == value_needed )
        pthread_exit(NULL);
}
+4
source share
2 answers

Here is your program cleaned up. It works without the above statement:

#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 is what I noticed when cleaning it:

  • for( i = 0; i < 5, i++ ) a semicolon means that the loop may not have worked

  • in test(), was thnot reset, which means that the unsuccessful pthread_createused a link to the old thread.

  • tfunc pthread_join if ( g_count == value_needed ), , .. pthread_join . . sleep(), .

  • .

, , , , , , - . , , .

, , .

+4

tpp.c: 63: __pthread_tpp_change_priority: Assertion :
https://sourceware.org/ml/libc-help/2008-05/msg00071.html , fast mutex recursive mutex, pthread_mutex_t . , pthread_mutex_t ?
BTW, , plz mutex PTHREAD_MUTEX_RECURSIVE_NP.

+2

Source: https://habr.com/ru/post/1527285/


All Articles