Beispiel #1
0
void sort(int *x, int n, int argc, char *argv[]) {
	struct args args;
	if (argc >= 3)
		cutoff = atoi(argv[2]);
	args.a = x;
	args.lb = 0;
	args.ub = n - 1;
	quick(&args);
	Thread_join(NULL);
}
Beispiel #2
0
int main(int argc, char *argv[]){
	int m = 5;
	int preempt;
	
	preempt = Thread_init(1, NULL);
	assert(preempt == 1);
	if (argc >= 2){
		m = atoi(argv[1]);
	}
	n = 0;
	// increment n unsafely
	{
		int i;
		for (i = 0; i < m; i++){
			Thread_new(unsafe, &n, 0, NULL);	// 创建m个线程
		}
		Thread_join(NULL);
	}
	
	Fmt_print("%d == %d\n", n, NBUMP * m);
	
	n = 0;
	// increment n safely
	{
		int i;
		struct args args;
		Sem_T mutex;
		Sem_init(&mutex, 1);
		args.mutex = &mutex;
		args.ip = &n;
		for (i = 0; i < m; i++){
			Thread_new(safe, &args, sizeof(args), NULL);
		}
		Thread_join(NULL);
	}
	
	Fmt_print("%d == %d\n", n, NBUMP * m);
	Thread_exit(EXIT_SUCCESS);
	
	return EXIT_SUCCESS;
}
Beispiel #3
0
int main(int argc, char *argv[]) {
        int i, j;
        int m = argc > 1 ? atoi(argv[1]) : 4;
        int n = argc > 2 ? atoi(argv[2]) : 3;

        Thread_init();
        Sem_init(&mutex, 1);
        for (j = 0; j < n; j++) {
                struct args args;
                args.mutex = &mutex;
                args.ip = &y;
                for (i = 0; i < m; i++)
                        Thread_new((int (*)(void *))incr, &args, sizeof args, NULL);
                Thread_join(0);
                if (y != m*10000)
                        printf("%d:%d\n", j, y);
                y = 0;
        }
        Thread_exit(0);
        return 0;
}
Beispiel #4
0
 void Thread::join()
 {
     if (!m_alive)
         return;
     Thread_join(m_handle);
 }