Пример #1
0
int
main() {
	struct thread t[THREADS];
	struct args args[THREADS];
	struct thread_event ev[THREADS];
	int i;
	for (i=0;i<THREADS;i++) {
		thread_event_create(&ev[i]);
		printf("create %d %p\n",i,&ev[i]);
		t[i].func = func;
		t[i].ud = &args[i];
		args[i].n = i;
		if (i+1<THREADS) {
			args[i].wait = &ev[i];
		} else {
			args[i].wait = NULL;
		}
		if (i-1 >=0) {
			args[i].trigger = &ev[i-1];
		} else {
			args[i].trigger = NULL;
		}
	}
	for(i=0;i<THREADS;i++) {
		thread_creat(&(t[i]));
	}
	thread_join(t, THREADS);
	for (i=0;i<THREADS;i++) {
		thread_event_release(&ev[i]);
	}

	return 0;
}
Пример #2
0
static int
lrun(lua_State *L) {
	check_schedule(L);
	int threads = schedule_threads(S);
	struct worker w[threads];
	struct thread t[threads];
	struct workshop ws;
	ws.threads = threads;
	ws.w = w;
	int i;
	for (i=0;i<threads;i++) {
		w[i].id = i;
		w[i].suspend = 0;
		w[i].workshop = &ws;
		thread_event_create(&w[i].event);
		t[i].func = worker_func;
		t[i].ud = &w[i];
	}
	thread_join(t,threads);
	for (i=0;i<threads;i++) {
		thread_event_release(&w[i].event);
	}
	return 0;
}