Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 25 Apr 1998 14:12:53 -0000
From:      "=?KOI8-R?Q?=FB=C1=D4=C1=C5=D7_=E1=CC=C5=CB=D3=C1=CE=C4=D2?=" <div@nsu.ru>
To:        "Q:FreeBSD" <freebsd-questions@FreeBSD.ORG>
Subject:   pthread question
Message-ID:  <199804250712.OAA17632@mx.nsu.ru>

next in thread | raw e-mail | index | archive | help
Это сообщение в формате MIME состоит из нескольких частей.

------=_NextPart_000_01BD7054.3C797B00
Content-Type: text/plain; charset=KOI8-R
Content-Transfer-Encoding: 7bit

Hi, all

I can not understand the reason of a problem with which I has met.
This problem consists in that that in multithread application
active thread  with no system calls references does not allow
other threads to work. I can demonstrate it by attached test program.
The purpose of this test is a reception of external timer for active 
thread which can has (in general) long periods of work without system
calls. Thus here is thread with blind infinite loop and initial thread 
with loop of interval sleep (usleep/setitimer, nanosleep, select 
timeout - no difference). On my system (2.2.6) initial thread creates 
child thread and goes to sleep, there is the context switch to child
thread without return - child thread runs forever.
Little history. I develop some virtual machine as a kernel for 
database engine. It runs some multithread (not a pthread) pseudocode
and uses external clock(SIGALRM/setitimer before) for context switching.
I'v used pthreads in this situation for my async IO system.
But after I have updated system (2.2.2 -> 2.2.6) there was the above 
mentioned problem. Sometimes signals are lost sometimes signal handlers,
select timeout wait realisation of external clock was unsuccessfull.
If you will have ideas on this occassion I shall be rather glad to listen.

Beforehand grateful, Boris Muratshin.



------=_NextPart_000_01BD7054.3C797B00
Content-Type: application/octet-stream; name="test2.cc"
Content-Transfer-Encoding: 7bit
Content-Description: test2.cc ()
Content-Disposition: attachment; filename="test2.cc"


#include <stdio.h>
#include <stdlib.h>
#include <signal.h>
#include <sys/time.h>
#include <sys/signal.h>
#include <pthread.h>
#include <unistd.h>

extern "C" int  nanosleep( const struct timespec* , struct timespec* );


void sigvt( int n)
{
 printf("---%d",n);
 fflush(0);
}

void *proc2( void*p )
{
  for (;;)
   {
    for (int j=0;j<10000000;j++);
//    printf("!");
//    fflush(0);
//    pthread_yield();
   }
  return NULL;
}
int main( )
{
 struct timespec ts={0,10000000};
 struct timeval  tv={0,10000};
 pthread_t thread2;
 pthread_create(&thread2,NULL,proc2,"bbb");
 
 for (;;)
  {
   printf("<");
   fflush(0);
   select(0,NULL,NULL,NULL,&tv);
//   usleep(10000);
//   nanosleep(&ts,NULL);
   printf(">");
   fflush(0);
  } 
 return 0;
}

------=_NextPart_000_01BD7054.3C797B00--


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



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