Ejemplo n.º 1
0
void * f(void * arg_) {
    arg_t * arg = (arg_t *)arg_;
    long a = arg->a, b = arg->b;
    long ninc_per_thread = arg->ninc_per_thread;
#if DBG
    printf("%ld : f(%ld,%ld)\n", myth_get_worker_num(), a, b);
#endif
    if (b - a == 1) {
        int i;
        for (i = 0; i < ninc_per_thread; i++) {
            myth_mutex_lock(arg->m);
            arg->p[0]++;
            myth_mutex_unlock(arg->m);
        }
        arg->r = a;
    } else {
        long c = (a + b) / 2;
        arg_t cargs[2] = { { ninc_per_thread, a, c, 0, arg->p, arg->m },
            { ninc_per_thread, c, b, 0, arg->p, arg->m }
        };
        myth_thread_t tid = myth_create(f, cargs);
        f(cargs + 1);
        myth_join(tid, 0);
        arg->r = cargs[0].r + cargs[1].r;
    }
    return 0;
}
Ejemplo n.º 2
0
int main() {
  void * res = 0;
  myth_thread_t th = myth_create(f, (void *)123);
  myth_join(th, &res);
  assert(res == (void *)579);
  printf("OK\n");
  return 0;
}
Ejemplo n.º 3
0
void accalt_tasklet_join(ACCALT_tasklet *tasklet) {
#ifdef ARGOBOTS
    ABT_task_free(tasklet);
#endif
#ifdef MASSIVETHREADS
    myth_join(*tasklet, NULL);
#endif
#ifdef QTHREADS
    qthread_readFF(NULL, tasklet);
#endif
}
Ejemplo n.º 4
0
void accalt_ult_join(ACCALT_ult *ult) {
#ifdef ARGOBOTS
    ABT_thread_free(ult);
#endif
#ifdef MASSIVETHREADS
    myth_join(*ult, NULL);
#endif
#ifdef QTHREADS
    qthread_readFF(NULL, ult);
#endif
}
Ejemplo n.º 5
0
void * f(void * arg_) {
  arg_t * arg = (arg_t *)arg_;
  long a = arg->a, b = arg->b;
  if (b - a == 1) {
    arg->r = a;
  } else {
    long c = (a + b) / 2;
    arg_t cargs[2] = { { a, c, 0 }, { c, b, 0 } };
    myth_thread_t tid = myth_create(f, cargs);
    f(cargs + 1);
    myth_join(tid, 0);
    arg->r = cargs[0].r + cargs[1].r;
  }
  return 0;
}
Ejemplo n.º 6
0
int main(int argc,char **argv)
{
	myth_init();
	myth_thread_t th=myth_create(test_thread,NULL);
	int i;
	for(i=0;i<YIELD_COUNT;i++){
#ifdef SHOW_LOG
		fprintf(stderr,"A%d\n",i);
#endif
		myth_yield2();
	}
	myth_join(th,NULL);
	myth_fini();
	printf("OK\n");
	return 0;
}
Ejemplo n.º 7
0
int main(int argc, char ** argv) {
    long nthreads        = (argc > 1 ? atol(argv[1]) : 50);
    long ninc_per_thread = (argc > 2 ? atol(argv[2]) : 1000);

    myth_mutex_init(m, 0);
    long p[1] = { 0 };
    arg_t arg[1] = { { ninc_per_thread, 0, nthreads, 0, p, m } };
    myth_thread_t tid = myth_create(f, arg);
    myth_join(tid, 0);

    if (arg->r == (nthreads - 1) * nthreads / 2
            && arg->p[0] == nthreads * ninc_per_thread) {
        printf("OK\n");
        return 0;
    } else {
        printf("NG: p = %ld != nthreads * ninc_per_thread = %ld\n",
               arg->p[0], nthreads * ninc_per_thread);
        return 1;
    }
}
Ejemplo n.º 8
0
int main(int argc, char ** argv) {
  long nthreads = (argc > 1 ? atol(argv[1]) : 100000);
  arg_t arg[1] = { { 0, nthreads, 0 } };
  long i;
  for (i = 0; i < 3; i++) {
    double t0 = cur_time();
    myth_thread_t tid = myth_create(f, arg);
    myth_join(tid, 0);
    double t1 = cur_time();
    double dt = t1 - t0;
    if (arg->r == (nthreads - 1) * nthreads / 2) {
      printf("OK\n");
      printf("%ld thread creation/join in %.9f sec (%.3f per sec)\n",
	     nthreads, dt, nthreads / dt);
    } else {
      printf("NG\n");
      return 1;
    }
  }
  return 0;
}
Ejemplo n.º 9
0
int create_and_delete_keys() {
  myth_thread_t th[n_keys];
  long i;
  for (i = 0; i < n_keys; i++) {
    keys[i] = 0;
  }
  for (i = 0; i < n_keys; i++) {
    th[i] = myth_create(f, (void *)i);
  }
  for (i = 0; i < n_keys; i++) {
    myth_join(th[i], 0);
  }
  for (i = 0; i < n_keys; i++) {
    assert(keys[i] == 1);
  }
  for (i = 0; i < n_keys; i++) {
    int r = myth_key_delete((myth_key_t)i);
    assert(r == 0);
  }
  return 0;
}