예제 #1
0
void dmtcp::initializeMtcpEngine()
{
  initializeDmtcpInfoInMtcp();

  mtcp_set_callbacks(&callbackSleepBetweenCheckpoint,
                     &callbackPreCheckpoint,
                     &callbackPostCheckpoint,
                     &callbackShouldCkptFD,
                     &callbackWriteCkptPrefix);

  mtcp_set_dmtcp_callbacks(&callbackHoldsAnyLocks,
                           &callbackPreSuspendUserThread,
                           &callbackPreResumeUserThread);

  JTRACE ("Calling mtcp_init");
  mtcp_init(UniquePid::getCkptFilename(), 0xBadF00d, 1);
  mtcp_ok();

  JTRACE ( "mtcp_init complete" ) ( UniquePid::getCkptFilename() );

  /* Now wait for Checkpoint Thread to finish initialization
   * NOTE: This should be the last thing in this constructor
   */
  ThreadSync::initMotherOfAll();
  while (!ThreadSync::isCheckpointThreadInitialized()) {
    struct timespec sleepTime = {0, 10*1000*1000};
    nanosleep(&sleepTime, NULL);
  }
}
int main () {
  mtcp_init ("testmtcp.mtcp", 3, 0);
  mtcp_ok ();

  while (1) {
     sleep (1);
  }
  return 0;
}
예제 #3
0
int main (int argc, char *argv[])

{
  char *p;
  int i;
  pthread_t thread_tid;

  if (argc != 4) goto usage;

  nproducers = strtol (argv[1], &p, 0);
  if ((*p != 0) || (nproducers <= 0) || (nproducers > 9)) {
    fprintf (stderr, "testmtcp4: invalid number_of_producers %s\n", argv[1]);
    goto usage;
  }

  babblesize = strtol (argv[2], &p, 0);
  if ((*p != 0) || (babblesize <= 0) || (babblesize * nproducers > 2*1024)) {
    fprintf (stderr, "testmtcp4: invalid number_of_megabytes %s\n", argv[2]);
    goto usage;
  }
  babblesize <<= 20;
  babblesize /= sizeof (int);
  for (l2babblesize = 0; (1 << l2babblesize) < babblesize; l2babblesize ++) { }

  niterations = strtol (argv[3], &p, 0);
  if ((*p != 0) || (niterations <= 0)) {
    fprintf (stderr, "testmtcp4: invalid number_of_iterations %s\n", argv[3]);
    goto usage;
  }

  mtcp_init ("testmtcp4.mtcp", 10, 1);
  mtcp_ok ();

  for (i = 0; i < nproducers; i ++) {
    if (pthread_create (&thread_tid, NULL, produca_func, NULL) < 0) {
      fprintf (stderr, "error creating produca: %s\n", strerror (errno));
      return (-1);
    }
  }

  consuma_func (NULL);
  return (0);

usage:
  fprintf (stderr, "usage: testmtcp4 <number_of_producers> <number_of_megabytes> <iterations>\n");
  fprintf (stderr, "   number_of_producers in range 1..9\n");
  fprintf (stderr, "   number_of_megabytes * number_of_producers <= 2G\n");
  fprintf (stderr, "   number_of_iterations to run producers\n");
  fprintf (stderr, "   an example is: testmtcp4 5 6 100\n");
  return (-1);
}