Esempio n. 1
0
int
threadtest2(int nargs, char **args)
{
	(void)nargs;
	(void)args;

	init_sem();
	kprintf("Starting thread test 2...\n");
	runthreads(0);
	kprintf("\nThread test 2 done.\n");

	return 0;
}
Esempio n. 2
0
int main()
{
    getcontext(&uctx_main);  //AMJAD: Added uctx_main
    int thread_num = 10;
    int j;
    char* thread_names[] = {
        "thread 0",
        "thread 1",
        "thread 2",
        "thread 3",
        "thread 4",
        "thread 5",
        "thread 6",
        "thread 7",
        "thread 8",
        "thread 9"
    };

    /* Initialize MyThreads library. */
    mythread_init();

    /* 250 ms */
    set_quantum_size(250);

    counter_mutex = create_semaphore(1);

    for(j=0; j<thread_num; j++)
    {
        mythread_create(thread_names[j], (void *) &handler, 6004);
    }

    /* Print threads informations before run */
    mythread_state();

    /* When this function returns, all threads should have exited. */
    runthreads();
    
    destroy_semaphore(counter_mutex);

    /* Print threads informations after run */
    mythread_state();

    printf("The counter is %d\n", counter);
    printf("The result is %f\n", result);

    if (counter == 50 &&
	(result - 151402.656521) < 0.000001)
      printf(">>> Thread library PASSED the Test 1\n");

    exit(0);
}
Esempio n. 3
0
int main()
{
    int thread_num = 10;
    int j;
    char* thread_names[] = {
        "thread 0",
        "thread 1",
        "thread 2",
        "thread 3",
        "thread 4",
        "thread 5",
        "thread 6",
        "thread 7",
        "thread 8",
        "thread 9"
    };

    /* Initialize MyThreads library. */
    init_my_threads();

    /* 250 ms */
    set_quantum_size(250);

    counter_mutex = create_semaphore(1);

    for(j=0; j<thread_num; j++)
    {
        create_my_thread(thread_names[j], (void *) &handler, 64000);
    }

    /* Print threads informations before run */
    my_threads_state();

    /* When this function returns, all threads should have exited. */
    runthreads();
    
    destroy_semaphore(counter_mutex);

    /* Print threads informations after run */
    my_threads_state();

    printf("The counter is %d\n", counter);
    printf("The result is %f\n", result);

    exit(0);
}
Esempio n. 4
0
int main (int argc, char *argv[])
{
#if defined(USE_LFH) && defined(_WIN32)
  // Activate 'Low Fragmentation Heap'.
  ULONG info = 2;
  HeapSetInformation (GetProcessHeap(),
		      HeapCompatibilityInformation,
		      &info,
		      sizeof(info));
#endif
#if 0 // defined(__SVR4)
 {
   psinfo_t ps;
   int pid = getpid();
   char fname[255];
   sprintf (fname, "/proc/%d/psinfo", pid);
   // sprintf (fname, "/proc/self/ps");
   FILE * f = fopen (fname, "rb");
   printf ("opening %s\n", fname);
   if (f) {
     fread (&ps, sizeof(ps), 1, f);
     printf ("resident set size = %dK\n", ps.pr_rssize);
     fclose (f);
   }
 }
#endif

#if defined(_MT) || defined(_REENTRANT)
  int          min_threads, max_threads ;
  int          num_rounds ;
  int          chperthread ;
#endif
  unsigned     seed=12345 ;
  int          num_chunks=10000;
  long sleep_cnt;

  if (argc > 7) {
    sleep_cnt = atoi(argv[1]);
    min_size = atoi(argv[2]);
    max_size = atoi(argv[3]);
    chperthread = atoi(argv[4]);
    num_rounds = atoi(argv[5]);
    seed = atoi(argv[6]);
    max_threads = atoi(argv[7]);
    min_threads = max_threads;
    printf ("sleep = %ld, min = %d, max = %d, per thread = %d, num rounds = %d, seed = %d, max_threads = %d, min_threads = %d\n",
	    sleep_cnt, min_size, max_size, chperthread, num_rounds, seed, max_threads, min_threads);
    goto DoneWithInput;
  }

#if defined(_MT) || defined(_REENTRANT)
  //#ifdef _MT
  printf( "\nMulti-threaded test driver \n") ;
#else
  printf( "\nSingle-threaded test driver \n") ;
#endif
#ifdef CPP
  printf("C++ version (new and delete)\n") ;
#else
  printf("C version (malloc and free)\n") ;
#endif
  printf("runtime (sec): ") ;
  scanf ("%ld", &sleep_cnt);

  printf("chunk size (min,max): ") ;
  scanf("%d %d", &min_size, &max_size ) ;
#if defined(_MT) || defined(_REENTRANT)
  //#ifdef _MT
  printf("threads (min, max):   ") ; 
  scanf("%d %d", &min_threads, &max_threads) ;
  printf("chunks/thread:  ") ; scanf("%d", &chperthread ) ;
  printf("no of rounds:   ") ; scanf("%d", &num_rounds ) ;
  num_chunks = max_threads*chperthread ;
#else 
  printf("no of chunks:  ") ; scanf("%d", &num_chunks ) ;
#endif
  printf("random seed:    ") ; scanf("%d", &seed) ;

 DoneWithInput:

  if( num_chunks > MAX_BLOCKS ){
    printf("Max %d chunks - exiting\n", MAX_BLOCKS ) ;
    return(1) ;
  }

#ifndef __WIN32__
#ifdef __SVR4
  pthread_setconcurrency (max_threads);
#endif
#endif

  lran2_init(&rgen, seed) ;
  // init_space = CountReservedSpace() ;

#if defined(_MT) || defined(_REENTRANT)
  //#ifdef _MT
  runthreads(sleep_cnt, min_threads, max_threads, chperthread, num_rounds) ;
#else
  runloops(sleep_cnt, num_chunks ) ;
#endif

#ifdef _DEBUG
  _cputs("Hit any key to exit...") ;	(void)_getch() ;
#endif

  return 0;

} /* main */
Esempio n. 5
0
File: larson.c Progetto: d-b/CSC469
int main (int argc, char *argv[])
{

#if defined(_MT) || defined(_REENTRANT)
  int          min_threads, max_threads ;
  int          num_rounds ;
  int          chperthread ;
#endif
  unsigned     seed=12345 ;
  int          num_chunks=10000;
  long sleep_cnt;
  int matches;

  if (argc > 7) {
    sleep_cnt = atoi(argv[1]);
    min_size = atoi(argv[2]);
    max_size = atoi(argv[3]);
    chperthread = atoi(argv[4]);
    num_rounds = atoi(argv[5]);
    seed = atoi(argv[6]);
    max_threads = atoi(argv[7]);
    min_threads = max_threads;
    goto DoneWithInput;
  }

#if defined(_MT) || defined(_REENTRANT)
  //#ifdef _MT
  printf( "\nMulti-threaded test driver \n") ;
#else
  printf( "\nSingle-threaded test driver \n") ;
#endif
  printf("C version (malloc and free)\n") ;

  printf("runtime (sec): ") ; /* 15 seconds */
  if ((matches = scanf ("%ld", &sleep_cnt)) != 1) {
	  printf("error scanning stdin for sleep_cnt - exiting\n");
	  return(1);
  }

  printf("chunk size (min,max): ") ; /* 8 40 */
  if ((matches = scanf("%d %d", &min_size, &max_size )) != 2) {
	  printf("error scanning stdin for chunk size (min,max) - exiting\n");
	  return(1);
  }

#if defined(_MT) || defined(_REENTRANT)
  //#ifdef _MT
  printf("threads (min, max):   ") ; /* same, 1 1, 2 2, etc. */
  if ((matches = scanf("%d %d", &min_threads, &max_threads)) != 2) {
	  printf("error scanning stdin for threads (min,max) - exiting\n");
	  return(1);
  }

  printf("chunks/thread:  ") ; 
  if ((matches = scanf("%d", &chperthread )) != 1) { /* 10K */
	  printf("error scanning stdin for chunks/thread - exiting\n");
	  return(1);
  }
	  
  printf("no of rounds:   ") ; 
  if ((matches = scanf("%d", &num_rounds )) != 1) {  /* 10 */
	  printf("error scanning stdin for no of rounds - exiting\n");
	  return(1);
  }
  num_chunks = max_threads*chperthread ;
#else 
  printf("no of chunks:  ") ; 
  if ((matches = scanf("%d", &num_chunks )) != 1) {
	  printf("error scanning stdin for no of chunks - exiting\n");
	  return(1);
  }	  
#endif
  printf("random seed:    ") ; 
  if ((matches = scanf("%d", &seed)) != 1) {
	  printf("error scanning stdin for random seed - exiting\n");
	  return(1);
  }	  	  
  printf("\n");
 DoneWithInput:

  if( num_chunks > MAX_BLOCKS ){
    printf("Max %d chunks - exiting\n", MAX_BLOCKS ) ;
    return(1) ;
  }

  pthread_setconcurrency (max_threads);

  lran2_init(&rgen, seed) ;

  // Call allocator-specific initialization function
  mm_init();

  numCPU=getNumProcessors();

#if defined(_MT) || defined(_REENTRANT)
  //#ifdef _MT
  runthreads(sleep_cnt, min_threads, max_threads, chperthread, num_rounds) ;
#else
  runloops(sleep_cnt, num_chunks ) ;
#endif

#ifdef _DEBUG
  _cputs("Hit any key to exit...") ;	(void)_getch() ;
#endif


  return(0) ;

} /* main */