Beispiel #1
0
static
void
concur(void)
{
	int i, fd;
	int r1, r2, w1;

	printf("Spawning 2 readers, 1 writer.\n");


	fd = open(FNAME, O_WRONLY|O_CREAT|O_TRUNC, 0664);
	if (fd < 0) {
		err(1, "[CONCUR]: %s: open", FNAME);
	}

	printf("Initializing test file: ");

	for (i = 0; i < SECTOR_SIZE + 1; i++) {
		cbuffer[i] = READCHAR;
	}

	for (i = 0; i < TMULT; i++) {
		write(fd, cbuffer, SECTOR_SIZE + 1);
	}


	close(fd);

	printf("Done initializing. Starting processes...\n");

	r1 = forkoff(subproc_read);
	w1 = forkoff(subproc_write);
	r2 = forkoff(subproc_read);

	printf("Waiting for processes.\n");

	dowait(r1);
	dowait(r2);
	dowait(w1);

	if (remove(FNAME)) {
		err(1, "[CONCUR]: %s: remove", FNAME);
	}

	printf("[CONCUR] Done!\n");
}
int
main (void)
{
  setbuf (stdout, NULL);
  printf ("main: %d\n", (int) getpid ());

  /* General hardware breakpoints and watchpoints validity.  */
  marker ();
  var++;
  /* Hardware watchpoints got disarmed here.  */
  forkoff (1);
  /* This watchpoint got lost before.  */
  var++;
  /* A sanity check for double hardware watchpoints removal.  */
  forkoff (2);
  var++;

  mark_exit ();
  return 0;
}
int
main (void)
{
  int i;
  void *thread_result;

  setbuf (stdout, NULL);
  printf ("main: %d\n", (int) gettid ());

  /* General hardware breakpoints and watchpoints validity.  */
  marker ();
  var++;	/* validity-first */
  empty ();	/* validity-first */

  i = pthread_create (&thread, NULL, start, NULL);
  assert (i == 0);

  var++;	/* validity-thread-A */
  empty ();	/* validity-thread-A */
  step = 1;
  while (step != 2)
    {
      i = pthread_yield ();
      assert (i == 0);
    }

  /* Hardware watchpoints got disarmed here.  */
  forkoff (1);

  var++;	/* after-fork1-A */
  empty ();	/* after-fork1-A */
  step = 3;
#ifdef FOLLOW_CHILD
  /* Spawn new thread as it was deleted in the child of FORK.  */
  i = pthread_create (&thread, NULL, start, NULL);
  assert (i == 0);
#endif
  while (step != 4)
    {
      i = pthread_yield ();
      assert (i == 0);
    }

  /* A sanity check for double hardware watchpoints removal.  */
  forkoff (2);

  var++;	/* after-fork2-A */
  empty ();	/* after-fork2-A */
  step = 5;
#ifdef FOLLOW_CHILD
  /* Spawn new thread as it was deleted in the child of FORK.  */
  i = pthread_create (&thread, NULL, start, NULL);
  assert (i == 0);
#endif

  i = pthread_join (thread, &thread_result);
  assert (i == 0);
  assert (thread_result == (void *) 5UL);

  mark_exit ();
  return 0;
}