Skip site navigation (1)Skip section navigation (2)
Date:      12 Jul 2001 20:45:52 +0200
From:      arno@heho.snv.jussieu.fr (Arno J. Klaassen)
To:        jasone@FreeBSD.ORG
Cc:        freebsd-stable@FreeBSD.ORG
Subject:   Changed behaviour of pthread_join (bug?)
Message-ID:  <wpbsmqq93z.fsf@heho.snv.jussieu.fr>

next in thread | raw e-mail | index | archive | help

Dear Sir,

since the recent (Jun 23 -- Jul 6) MFCs in lib/libc_r/uthread, our pthread programs
don't function any longer. The problem is that a joining a thread which
has been cancelled, either fails (with errno <3>) or hangs
in _thread_sys_poll :


gdb -core join_bug-bsd.core
  GNU gdb 4.18
  Core was generated by `join_bug-bsd'.
  Program terminated with signal 3, Quit.
  Reading symbols from /usr/lib/libc_r.so.4...done.
  Reading symbols from /usr/libexec/ld-elf.so.1...done.
  #0  0x280bb000 in _thread_sys_poll () from /usr/lib/libc_r.so.4
  (gdb) where
  #0  0x280bb000 in _thread_sys_poll () from /usr/lib/libc_r.so.4
  #1  0x280ba365 in _thread_kern_sched_state_unlock () from /usr/lib/libc_r.so.4
  #2  0x280b9c64 in _thread_kern_scheduler () from /usr/lib/libc_r.so.4
  #3  0x0 in ?? ()
  (gdb) 

At the end of this mail you find a simple code fragment which produces
this behaviour. This code runs perfectly well under Solaris2.5 as well
as well as on a 4.3-STABLE #0: Sun Jun 10 00:24:49 MEST 2001 box.

Thanx in advance.


  Arno J. Klaassen


-- 

  SCITO S.A.                   INSERM U483
  Le Grand Sablon              University Pierre et Marie Curie
  4, avenue de l'Obiou         9, quai Saint Bernard
  38700 La Tronche             75 252 Paris Cedex 5

  +33 - 1 - 44 27 33 87
  arno@ccr.jussieu.fr


###################################################################
#include <stdio.h>                       
#include <stdlib.h>
#include <sys/types.h>
#include <sys/time.h>
#include <sys/resource.h>
#include <errno.h>
#include <pthread.h>

pthread_t control_thread;
pthread_t scheduler_thread;

#define NR_OF_ITERATIONS 500000
#define NR_OF_TESTMIPS_THREADS 10

static void *
testmips (void *data)
{
  int i;
  int a = 2;
  int b = 3;

  for (i = 1; i <= NR_OF_ITERATIONS; i++)
    {
      a += (b / a);
      a -= (b / a);
    }

  return NULL;
}

static void *
scheduler (void * data)
{
  int i = 0;
  int ret = 0;
  pthread_t testmips_thread;

  for (i = 1; i <= NR_OF_TESTMIPS_THREADS; i++)
    {
      pthread_testcancel();

      fprintf (stderr, "Starting new testmips_thread <%d>.\n", i);

      pthread_create (&testmips_thread, 0, testmips, NULL);
      ret = pthread_join (testmips_thread, NULL);
      if (ret != 0)
        fprintf(stderr, "  FAILED to join testmips_thread.\n");
      else
        fprintf(stderr, "  Successfully joined testmips_thread.\n");
    }
  
  fprintf (stderr, "Routine 'scheduler' finished.\n");

  fprintf(stderr, "\nPRESS ENTER TO STOP.\n\n");

  scheduler_thread = NULL;

  return NULL;
}


static void *
control_routine (void * data)
{
  int ret;

  fprintf(stderr, "PRESS ENTER TO CANCEL THE TESTMIPS SCHEDULER.\n\n");
  getchar();

  if (scheduler_thread != NULL)
    {
      fprintf(stderr, "\n  Canceling scheduler_thread.\n");
      ret = pthread_cancel (scheduler_thread);
      if (ret != 0)
        {
          fprintf(stderr, "  FAILED to cancel scheduler_thread.\n");
          fprintf(stderr, "  Errno nr is <%d>.\n", errno);
        }
    
      fprintf(stderr, "  Trying to join scheduler_thread.\n");
      ret = pthread_join (scheduler_thread, NULL);
      if (ret != 0)
        {
          fprintf(stderr, "  FAILED to join scheduler_thread with errno <%d>.\n", errno);
        }
      else
        fprintf(stderr, "  Successfully joined scheduler_thread.\n");
    }

  fprintf (stderr, "Routine 'control_routine' finished.\n");

/*  control_thread = NULL;*/

  return NULL;
}

static void
do_the_job(void)
{
  pthread_create (&scheduler_thread, 0, scheduler, NULL);
}

int
main (int argc, char *argv[])
{
  int ret;

  pthread_create (&control_thread, 0, control_routine, NULL);
  do_the_job();

  ret = pthread_join (control_thread, NULL);
  if (ret != 0)
    fprintf(stderr, "  FAILED to join control_thread.\n");

  return 0;
}

To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-stable" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?wpbsmqq93z.fsf>