예제 #1
0
파일: myth_lock.c 프로젝트: rchyena/chapel
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;
}
예제 #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;
}
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;
}
예제 #4
0
파일: accalt.c 프로젝트: adcastel/ULT_work
void accalt_tasklet_creation(void(*thread_func)(void *), void *arg, ACCALT_tasklet *new_ult) {
#ifdef ARGOBOTS
    ABT_xstream xstream;
    ABT_xstream_self(&xstream);
    ABT_pool pool;
    ABT_xstream_get_main_pools(xstream, 1, &pool);
    ABT_task_create(pool, thread_func, arg, new_ult);
#endif
#ifdef MASSIVETHREADS
    *new_ult = myth_create((void *) thread_func, arg);
#endif
#ifdef QTHREADS
    qthread_fork((void *) thread_func, arg, new_ult);
#endif
}
예제 #5
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;
}
예제 #6
0
파일: myth_lock.c 프로젝트: rchyena/chapel
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;
    }
}
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;
}
예제 #8
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;
}
예제 #9
0
//
// Have the tasking layer create a dedicated task to help the
// communication layer by running function 'fn' with argument 'arg'.
// This task should be quite dedicated (e.g., get its own system
// thread) in order to be responsive and not be held up by other
// user-level tasks. returns 0 on success, nonzero on failure.
//
int chpl_task_createCommTask(chpl_fn_p fn, void* arg) {
  // return chpl_thread_createCommThread(fn, arg);
  myth_create((myth_func_t)fn, arg);
  return 0;
}