IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 41483 for trunk


Ignore:
Timestamp:
Feb 3, 2021, 2:12:35 PM (5 years ago)
Author:
eugene
Message:

stop threads before freeing data when QUIT is called; fuzz added to last task execution was not correctly added to usec -- this made fast tasks run many invalid attempts

Location:
trunk/Ohana/src/opihi
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • trunk/Ohana/src/opihi/include/pantasks.h

    r40424 r41483  
    265265int  DeleteClient (int client);
    266266void *ListenClients (void *data);
     267void QuitClientThread (void);
    267268
    268269// functions related to the server threads
    269270void *CheckJobsAndTasksThread (void *data);
     271void QuitJobsAndTasksThread (void);
     272void QuitControllerThread (void);
    270273
    271274void CheckTasksSetState (int state);
  • trunk/Ohana/src/opihi/lib.shell/gprint.c

    r38986 r41483  
    304304
    305305  if (stream[0].mode == GP_FILE) {
     306    // fprintf (stderr, "printing to %s, mode FILE, thread %d\n", stream[0].name, (int) stream[0].thread);
    306307    status = vfprintf (stream[0].file, format, argp);
    307308    fflush (stream[0].file);
     
    310311    }
    311312  } else {
     313    // fprintf (stderr, "printing to %s, mode BUFF, thread %d\n", stream[0].name, (int) stream[0].thread);
    312314    vPrintIOBuffer (stream[0].buffer, format, argp);
    313315  }
  • trunk/Ohana/src/opihi/pantasks/CheckTasks.c

    r38986 r41483  
    5252    // XXX this should be optional
    5353    fuzz = task[0].exec_period*(0.5*drand48() - 0.25);
    54     task[0].last.tv_usec = 1e6*(fuzz - (int)fuzz);
     54    task[0].last.tv_usec += 1e6*(fuzz - (int)fuzz);
    5555    task[0].last.tv_sec += (int) fuzz;
    5656
  • trunk/Ohana/src/opihi/pantasks/ListenClients.c

    r39457 r41483  
    77static int *clients;
    88static IOBuffer **buffers;
     9
     10static int ClientThreadRuns = TRUE;
     11
     12void QuitClientThread (void) {
     13  ClientThreadRuns = FALSE;
     14}
    915
    1016void InitClients () {
     
    8389  gprintSetBuffer (GP_ERR);
    8490
    85   while (1) {
     91  while (ClientThreadRuns) {
    8692
    8793    /* Wait up to 0.5 second - need to timeout to update client list */
     
    174180    /* check if we need to shut down the thread */
    175181  }
     182  return NULL;
    176183}
    177184
  • trunk/Ohana/src/opihi/pantasks/controller_threads.c

    r39457 r41483  
    55static int CheckControllerRun = FALSE;
    66
     7static int ControllerThreadRuns = TRUE;
     8
    79void CheckControllerSetState (int state) {
    810  CheckControllerRun = state;
     
    1012int CheckControllerGetState () {
    1113  return (CheckControllerRun);
     14}
     15
     16void QuitControllerThread (void) {
     17  ControllerThreadRuns = FALSE;
    1218}
    1319
     
    2632  }
    2733
    28   while (1) {
     34  while (ControllerThreadRuns) {
    2935
    3036    // check for thread suspend
     
    4753    usleep (500000); // allow other threads a chance to run
    4854  }
     55  return NULL;
    4956}
  • trunk/Ohana/src/opihi/pantasks/jobs_and_tasks_thread.c

    r39457 r41483  
    55static int CheckTasksRun = FALSE;
    66static int CheckJobsRun = FALSE;
     7
     8static int JobsAndTasksThreadRuns = TRUE;
    79
    810void CheckJobsSetState (int state) {
     
    2325}
    2426
     27void QuitJobsAndTasksThread (void) {
     28  JobsAndTasksThreadRuns = FALSE; 
     29}
     30
    2531void *CheckJobsAndTasksThread (void *data) {
    2632  OHANA_UNUSED_PARAM(data);
     
    3945  }
    4046
    41   while (1) {
     47  while (JobsAndTasksThreadRuns) {
    4248
    4349    // one run of the task checker
     
    6369    }     
    6470  }
     71  return NULL;
    6572}
    6673
  • trunk/Ohana/src/opihi/pantasks/pantasks.c.in

    r39457 r41483  
    77# define opihi_rcfile ".pantasksrc"
    88
     9static pthread_t JobsAndTasksThread;
     10static pthread_t controllerThread;
     11
    912/* program-dependent initialization */
    1013void program_init (int *argc, char **argv) {
     
    1215  OHANA_UNUSED_PARAM(argv);
    1316 
    14   pthread_t JobsAndTasksThread;
    15   pthread_t controllerThread;
    16 
    1717  auto_break = TRUE;
    1818
     
    6767/* add program-dependent exit functions here */
    6868void cleanup () {
     69  // stop the threads before calling the free functions
    6970  QuitKapa ();
    7071  QuitController ();
    7172  ConfigFree ();
     73
     74  // tell the threads to exit and wait for them to exit
     75  QuitJobsAndTasksThread(); pthread_join (JobsAndTasksThread, NULL);
     76  QuitControllerThread(); pthread_join (controllerThread, NULL);
    7277
    7378  FreeBasic ();
  • trunk/Ohana/src/opihi/pantasks/pantasks_server.c.in

    r39457 r41483  
    1515void special_init (int *argc, char **argv);
    1616
     17static pthread_t JobsAndTasksThread;
     18static pthread_t controllerThread;
     19static pthread_t clientsThread;
     20
    1721/* program-dependent initialization */
    1822int main (int argc, char **argv) {
     
    2024  char hostname[256], portinfo[256];
    2125  char log_stdout[1024], log_stderr[1024], tmpname[1024];
    22   pthread_t JobsAndTasksThread;
    23   pthread_t clientsThread;
    24   pthread_t controllerThread;
    2526  int InitSocket, BindSocket;
    2627  SockAddress Address;
     
    136137  QuitController ();
    137138  ConfigFree ();
     139
     140  QuitJobsAndTasksThread(); pthread_join (JobsAndTasksThread, NULL);
     141  QuitControllerThread();   pthread_join (controllerThread, NULL);
     142  QuitClientThread();       pthread_join (clientsThread, NULL);
     143
    138144  InitBasic ();
    139145  InitData ();
Note: See TracChangeset for help on using the changeset viewer.