Exemple #1
0
int main() {
	gtthread_t t1, t2, t3, t4, t5;
	gtthread_init(1000);

	gtthread_create(&t1, func1, &t1);
	g_gtt = t1;
	gtthread_join(t1, NULL);

	gtt_tuple tuple;
	gtthread_create(&t2, func2, &tuple);
	tuple = (gtt_tuple) {
		.gtt1 = t1,
		.gtt2 = t2
	};
	gtthread_join(t2, NULL);

	gtthread_create(&t3, func3, NULL);
	g_gtt = t3;
	void *t3_self;
	gtthread_join(t3, &t3_self);

	gtthread_create(&t4, func4, t3_self);
	gtthread_join(t4, NULL);
	free(t3_self);

	gtthread_create(&t5, func5, NULL);
	volatile int x = 100000000;
	while(--x);
	void *msg;
	gtthread_join(t5, &msg);
	printf("%s\n", (char*) msg);

	return 0;
}
Exemple #2
0
int main() {
	gtthread_t t1, t2, t3, t4, t5;

	gtthread_init(1000);
	gtthread_mutex_init(&gttm);

	gtthread_create(&t1, func1, (void*) 1);
	gtthread_create(&t2, func1, (void*) 2);
	gtthread_join(t1, NULL);
	gtthread_join(t2, NULL);

	gtthread_mutex_lock(&gttm);
	gtthread_create(&t3, func2, (void*) 3);
	gtthread_create(&t4, func2, (void*) 4);
	printf("This should print before threads 3 and 4 finish\n");
	gtthread_mutex_unlock(&gttm);
	gtthread_join(t3, NULL);
	gtthread_join(t4, NULL);

	printf("Testing yield with one schedulable thread... ");
	gtthread_yield();
	gtthread_yield();
	gtthread_yield();
	printf("done!\n");

	printf("Deadlocking with thread 5...\n");
	gtthread_mutex_lock(&gttm);
	gtthread_create(&t5, func3, NULL);
	gtthread_join(t5, NULL);
	gtthread_mutex_unlock(&gttm);
	printf("!!! ERROR !!! Failed to deadlock with thread 5\n");

	return 0;
}
Exemple #3
0
int main() {
  int i;
  gtthread_t t1, t2, t3, t6;
  void *ret;

  gtthread_mutex_init(&count_lock);

  gtthread_init(5);
  gtthread_create(&t1, thr1, (void *) 1);
  gtthread_create(&t2, thr2, (void *) 2);
  gtthread_create(&t3, thr3, (void *) 3);
  gtthread_create(&t6, thr6, (void *) 6);

  for (i = 0; i < LOOP_MAX; i++) {
    printf("Main thread!\n");
    fflush(stdout);

    gtthread_mutex_lock(&count_lock);
    count++;
    gtthread_mutex_unlock(&count_lock);

    if (i % YIELD_VAL == 0) {
      gtthread_yield();
    }
  }

  printf("main waiting for thr1...\n");
  fflush(stdout);
  gtthread_join(t1, &ret);
  printf("thr1 joined main with value %d!\n", (int) ret);
  fflush(stdout);

  gtthread_cancel(t2);
  printf("thr2 cancelled!\n");
  fflush(stdout);

  printf("main waiting for thr3...\n");
  fflush(stdout);
  gtthread_join(t3, &ret);
  printf("thr3 joined main with value %d!\n", (int) ret);
  fflush(stdout);

  printf("main waiting for thr6...\n");
  fflush(stdout);
  gtthread_join(t6, &ret);
  printf("thr6 joined main with value %d!\n", (int) ret);
  fflush(stdout);

  gtthread_mutex_lock(&count_lock);
  printf("Final count value: %lu\n", count);
  fflush(stdout);
  gtthread_mutex_unlock(&count_lock);

  gtthread_mutex_destroy(&count_lock);
  return EXIT_SUCCESS;
}
Exemple #4
0
int main() {
    printf("test4d. Should print 'Success' three times.\n");

    gtthread_init(50000L);
    gtthread_create( &t1, thr1, NULL);
    gtthread_create( &t2, thr2, NULL);
    gtthread_join(t2, NULL);
    gtthread_join(t1, NULL);
    printf("Success\n");
    return EXIT_SUCCESS;
}
Exemple #5
0
int main()
{
	int rc;

	gtthread_init(1000);

	rc = gtthread_create(&g_th1, worker, NULL);
	rc = gtthread_create(&g_th2, worker, NULL);

	gtthread_join(g_th1, NULL);
	gtthread_join(g_th2, NULL);
	return 0;
}
Exemple #6
0
int main() {
    printf("test6b. Should print 'main hello' then 'thr1 hello' and 'thr2 hello' for 5 times interleaving (but no mixed up prints e.g. 'th1 thr2 hello hello')\n");

    gtthread_init(50000L);
    gtthread_mutex_init(&g_mutex);
    gtthread_mutex_lock(&g_mutex);

    gtthread_create( &t1, thr1, NULL);
    gtthread_create( &t2, thr2, NULL);
    gtthread_yield();
    printf("main hello\n");
    gtthread_mutex_unlock(&g_mutex);
    gtthread_join(t2, NULL);
    gtthread_join(t1, NULL);
    return EXIT_SUCCESS;
}
Exemple #7
0
int main()
{
        printf("Should not print any errors.\n");
	long i;
	gtthread_t threads[NUM_THREADS];

	gtthread_init(1000);

	gtthread_mutex_init(&g_mutex);

	for (i = 0; i < NUM_THREADS; ++i) {
		gtthread_create(&threads[i], worker, (void*) i);
	}

	for (i = 0; i < NUM_THREADS; ++i) {
		gtthread_join(threads[i], NULL);
	}

	if (g_num != NUM_THREADS) {
		fprintf(stderr, 
				"!ERROR! Wrong result! %d != %d\n",
				g_num, NUM_THREADS);
	}
	return 0;
}
Exemple #8
0
int main()
{
    int ndx, odx;
    void* status = (void*)100;
    printf("test thread create, cancel, join\n");
    printf("main: enter\n");
    gtthread_init(period);
    gtthread_yield();
    for(odx=0; odx<10; ++odx) {
        //gtthread_create( &t[odx], thrX, (void*)odx);
        //gtthread_create( &t[odx], thrR, (void*)odx);
        gtthread_create( &t[odx], thrY, (void*)odx);
    }
    gtthread_yield();
    for(ndx=0; ndx<20; ++ndx) {
            usleep(100*1000);
            puts(">");
            gtthread_yield();
    }
    for(odx=0; odx<10; ++odx) {
        gtthread_join( t[odx], &status);
        printf("thread %d return %d\n",odx,(long)status);
    }
    printf("main: exit\n");
    fflush(stdout);
    return EXIT_SUCCESS;
}
Exemple #9
0
int main()
{
    int ndx, tdx;
    void* status = (void*)100;
    int result;
    printf("test thread create N, join N\n");
    printf("main: enter\n");
    gtthread_init(period);
    gtthread_yield();
    for(tdx=0; tdx<1000; ++tdx) {
        gtthread_create( &t[tdx], thrX, (void*)tdx);
        //gtthread_create( &t[tdx], thrR, (void*)tdx);
        //gtthread_create( &t[tdx], thrY, (void*)tdx);
    }
    puts(">");
    gtthread_yield();
    for(tdx=0; tdx<1000; ++tdx) {
        result = gtthread_join( t[tdx], &status);
        if(result) printf("main.join %d\n",result);
        printf("thread %d return %d\n",tdx,(long)status);
    }
    printf("main: exit\n");
    fflush(stdout);
    return EXIT_SUCCESS;
}
Exemple #10
0
void *thr3(void *in) {
  int i, j = 0;
  void *ret;
  gtthread_t t4;

  printf("thr3 started with parameter %d\n", (int) in);
  fflush(stdout);

  gtthread_create(&t4, thr4, (void *) 4);

  for (i = 0; i < LOOP_MAX; i++) { 
    printf("thr3!\n");
    fflush(stdout);
    j++;

    if (i % YIELD_VAL == 0) {
      gtthread_yield();
    }

  }

  gtthread_join(t4, &ret);
  printf("thr4 joined thr3 with value %d!\n", (int) ret);
  fflush(stdout);

  printf("thr3 finished with parameter %d\n", (int) in);
  fflush(stdout);

  return (void *) j + 3;
}
Exemple #11
0
int main()
{
        printf("Should print 'thread 1 (3x) then thread 0 (3x).\n");
	gtthread_t th1, th2;

	gtthread_init(1000);

	gtthread_mutex_init(&g_mutex);

	gtthread_create(&th1, worker, (void*)1);
	gtthread_create(&th2, worker, (void*)2);

	gtthread_join(th1, NULL);
	gtthread_join(th2, NULL);
	return 0;
}
Exemple #12
0
void *thr2(void *in) {
  int i, j = 0;
  void *ret;
  gtthread_t t5;

  printf("thr2 started with parameter %d\n", (int) in);
  fflush(stdout);

  gtthread_create(&t5, thr5, NULL);

  for (i = 0; i < (LOOP_MAX + (LOOP_MAX / 2)); i++) { 
    printf("thr2!\n");
    fflush(stdout);
    j++;
    if (i % YIELD_VAL == 0) {
      gtthread_yield();
    }
  }

  gtthread_join(t5, NULL);
  printf("thr5 joined thr2 with value %d!\n", (int) ret);
  fflush(stdout);

  printf("thr2 finished with parameter %d\n", (int) in);
  fflush(stdout);

  return (void *) j + 2;
}
Exemple #13
0
int main()
{
	gtthread_t threads[NUM_THREADS];
	void* rets[NUM_THREADS];
	int i = 0;

	srand(time(NULL));

	// Randomly assign return values
	for (i = 0; i < NUM_THREADS; ++i) {
		g_return_values[i] = rand();
	}

	gtthread_init(1000);

	for (i = 0; i < NUM_THREADS; ++i) {
		gtthread_create(&threads[i], worker, (void*) i);
	}

	for (i = 0; i < NUM_THREADS; ++i) {
		gtthread_join(threads[i], &rets[i]);
		printf("Join on Thread[%d]", i);
	}

	// Check return values
	for (i = 0; i < NUM_THREADS; ++i) {
		if ((long) rets[i] != g_return_values[i]) {
			fprintf(stderr, 
					"!ERROR! %dth return value is wrong! %d, %d\n",
					i, rets[i], g_return_values[i]);
		}
	}
printf("Main exit\n");
	return 0;
}
Exemple #14
0
int main() {
int i;
char *a; 
void *b;
int c = 1000000;
    gtthread_init(100000L);
	gtthread_mutex_init(&g_mutex);
	//gtthread_mutex_lock(&g_mutex);
   	gtthread_create( &t1, thr1, &c);


				//printf("id:%d\n", t1);
	//while(c--);
   	gtthread_create( &t2, thr1, &c);  
			//	printf("id:%d\n", t2); 
	//printf("Exiting Main\n"); 


	//	while(1);
	/*for (i = 0; i< 5; i++){

	printf("Exiting Main\n");
	while(c--);
c = 1000000;}*/
	//gtthread_mutex_unlock(&g_mutex);
	//gtthread_yield();
	//gtthread_exit(NULL);	
	//gtthread_mutex_lock(&g_mutex);
   	//gtthread_create( &t1, thr1, &c);
	//gtthread_mutex_unlock(&g_mutex);

//	gtthread_join(t1, &b);
	//printf("b:%s\n", (char*) b);
	//gtthread_join(t2, &b);

				//a = (int*) killed[0].ret;



		//gtthread_yield();

while(1);
//gtthread_cancel(t1);
//gtthread_exit(NULL);

    return EXIT_SUCCESS;
}
Exemple #15
0
int main() {
	gtthread_t t1, t2, t3;
	gtthread_init(1000);

	gtthread_create(&t1, func1, NULL);
	gtthread_create(&t2, func2, NULL);
	gtthread_create(&t3, func3, NULL);

	void *msg;
	gtthread_join(t2, &msg);
	printf("%s\n", (char*) msg);
	free(msg);

	printf("main thread exiting...\n");
	gtthread_exit(NULL);
	return 0;
}
Exemple #16
0
int main() {
  printf("test4c. Should print 'Success'.\n");

  gtthread_init(50000L);
  gtthread_create( &t, thr, NULL);
  gtthread_exit(NULL);
  return EXIT_SUCCESS;
}
Exemple #17
0
int main() {
	gtthread_t t1;
	gtthread_t t2;
	gtthread_t t3;
	double sum_thread1 = 0;
	double *p1 = &sum_thread1;
	double **p2 = &p1;

	gtthread_mutex_init(&g_mutex);

	gtthread_init(10000);

	gtthread_create(&t1, thr1, NULL );

	gtthread_create(&t2, thr2, NULL );

	gtthread_create(&t3, thr3, NULL );

	printf("id of thread1 is %d\n", t1.id);
	printf("id of thread1 is %d\n", t2.id);
	// get self id
	gtthread_t t0;
	t0 = gtthread_self();
	printf("The main thread is %d \n", t0.id);

	//gtthread_yield();
	//gtthread_cancel(t2);

	gtthread_join(t1, (void **) p2);
	printf("Returned Value from thread 1 = %f\n", **p2);

	gtthread_join(t2, NULL );
	gtthread_join(t3, NULL );



	printf("returning to main thread!\n");

	// printf("returning to main thread again!\n");
	gtthread_mutex_destroy(&g_mutex);

    printf("\n....Exiting the Main!....\n");

	return EXIT_SUCCESS;
}
Exemple #18
0
int main(){

	gtthread_init(10000);

	gtthread_mutex_init(&m1);
	gtthread_mutex_init(&m2);
	gtthread_mutex_init(&m3);
	gtthread_mutex_init(&m4);
	gtthread_mutex_init(&m5);
	gtthread_create(&t1, philosopher, (void*)1);
	gtthread_create(&t2, philosopher, (void*)2);
	gtthread_create(&t3, philosopher, (void*)3);
	gtthread_create(&t4, philosopher, (void*)4);
	gtthread_create(&t5, philosopher, (void*)5);

	while(1);

}
Exemple #19
0
int main()
{
    void* status = (void*)100;
    printf("test mutex lock, unlock\n");
    printf("main: enter\n");
    gtthread_init(period);
    gtthread_mutex_init(period);
    for( ndx=0; ndx<5; ++ndx ) {
        gtthread_create( &t[ndx], thrX, status);
        gtthread_create( &t[ndx+10], thrR, status);
    }
    for( ndx=0; ndx<5; ++ndx ) {
        gtthread_join( t[1], &status);
    }
    printf("main: exit\n");
    fflush(stdout);
    return EXIT_SUCCESS;
}
Exemple #20
0
void main () {
	int i;
	gtthread_init(100000);
	for (i=0; i<5; i++) {
		gtthread_mutex_init(&chopstick[i]);
		gtthread_create(&philosopher[i], (void *)dining, (int *)(i+1));
	}
	gtthread_exit(NULL);
}
Exemple #21
0
int main() {
    gtthread_t t1;

    gtthread_init(50000L);
    gtthread_create( &t1, thr1, NULL);

    while(1);

    return EXIT_SUCCESS;
}
int main() {
  gtthread_init(1000);

  void * r1, * r2, * r3;
  gtthread_t t1, t2, t3;

  gtthread_create(&t1, thr1, 1);
  gtthread_join(t1, &r1);

  gtthread_create(&t2, thr1, r1);
  gtthread_join(t2, &r2);

  gtthread_create(&t3, thr1, r2);
  gtthread_join(t3, &r3);
  
  printf("return value: %d\n", r3);
  fflush(stdout);
  return 0;

  //return value should be 8
}
Exemple #23
0
int main() {
    gtthread_init(3000);
    gtthread_t philosopher[5];
    int i;
    for(i = 0; i < 5; i++) {
        gtthread_create(&philosopher[i], (void *) whateverphilosophersaresupposedtodo, (void *) i);
        chopstick[i] = malloc(sizeof(gtthread_mutex_t));
        gtthread_mutex_init(chopstick[i]);
    }
    while(1);
    return 0;
}
Exemple #24
0
int main()
{
	gtthread_t th1;

	gtthread_init(1000);

	gtthread_create(&th1, worker, NULL);

	printf("main exit\n");

	gtthread_exit(NULL);
	return 0;
}
Exemple #25
0
int main() {
  printf("test4b. Should print 'Success'.\n");

  gtthread_init(50000L);
  gtthread_t t;
  gtthread_create( &t, thr, NULL);
  if(gtthread_equal(gtthread_self(), t)) {
    printf("Failure.");
  } else {
    printf("Success");
  }
  return EXIT_SUCCESS;
}
int main(void) {

	gtthread_t ids[N];
	gtthread_init(1000L);
	gtthread_mutex_init(&g_mutex);

	gtthread_t threads[N];
	for(i = 0; i<N; i++) {
		gtthread_create(&threads[i], main_loop, (void*)i);
	}
	while(1);

}
Exemple #27
0
int main()
{
    gtthread_t threads[NO_OF_PHILOSOPHERS];
    int i = 0;

    gtthread_init(500);	

    for(i = 0; i < NO_OF_PHILOSOPHERS; i++)
    {
        threads[i] = (gtthread_t*)malloc(sizeof(gtthread_t));
        gtthread_create(threads[i], &perform, (void*)&i);
    }

    return 0;
}
Exemple #28
0
int main()
{
    gtthread_t t1;
    gtthread_t t2;
    gtthread_t t3;
    double sum_thread1 = 0;
    double *p1 = &sum_thread1;
    double **p2 = &p1;

    gtthread_mutex_init(&g_mutex);
    gtthread_init(1000);
    gtthread_create(&t1, thr1, NULL );
    printf("thread1 id %ld\n", t1); //t1.id);
    gtthread_create(&t2, thr2, NULL );
    printf("thread2 id %ld\n", t2); //t2.id);
    gtthread_create(&t3, thr3, NULL );
    printf("thread3 id %ld\n", t3); //t2.id);

    // get self id
    gtthread_t t0;
    t0 = gtthread_self();
    printf("main thread id %ld \n", t0); //t0.id);
    //gtthread_yield();
    gtthread_cancel(t2);
    //gtthread_join(t1, NULL);
    gtthread_join(t1, p2);
    printf("thread1 return = %f\n", **p2);
    gtthread_join(t2, NULL );
    gtthread_join(t3, NULL );

    printf("returning to main thread!\n");
    // printf("returning to main thread again!\n");
    gtthread_mutex_destroy(&g_mutex);
    printf("\n....Exiting the Main!....\n");
    return EXIT_SUCCESS;
}
Exemple #29
0
int main() {
	printf("gtthread_init\n");
	fflush(stdout);
  	gtthread_t t1,t2,t3;
	fflush(stdout);
  	gtthread_init(1);
	int a = 1;
	int b = 2;
	int c = 3;
  	gtthread_create( &t1, thr1, &a);
	gtthread_create( &t2, thr1, &b);
	gtthread_create( &t3, thr1, &c);
	printf("create finish\n");
	//fflush(stdout);
	int j = 0;
	long i;
	while(j != 10){
		i = 0;
		while(i<100000){
			i++;
			//printf("***\n");
		}
		printf ("main\n");
		fflush(stdout);
		//printf("self id = %d\n",gtthread_self().id);
		j++;
		//gtthread_yield();	
		
	}
	gtthread_cancel(t1);
	printf("main finish\n");
	gtthread_exit(0);
  //gtthread_yield();

  //return EXIT_SUCCESS;
}
Exemple #30
0
void main(){
	gtthread_init( 1000 );
	int i;


	gtthread_mutex_init(&test);
	for (i = 0; i < 10; i++)
    	        gtthread_create (&threads[i], thread_func, (void *)i);
  	    for (i = 0; i < 10; i++)
  	    {
    	        //gtthread_join (threads[i], NULL);
    	        //printf("Thread[%d] has exited\n", i);
  	    }
  	    usleep(10000000);
  	    printf("Main exit\n");
}