コード例 #1
0
ファイル: mytest.c プロジェクト: Aliced3645/os
int
main(int ac, char **av)
{
    int	i;

    uthread_init();
    
    uthread_mtx_init(&mtx1);
    uthread_mtx_init(&mtx2);
    uthread_mtx_init(&mtx3);

    uthread_cond_init(&cond);
    
    void (*tester[3]) (long a0, void* a1);
    tester[0] = tester1;
    tester[1] = tester2;
    tester[2] = tester3;

    for (i = 0; i < NUM_THREADS; i++)
    {
        
        uthread_create(&thr[i], tester[i], i, NULL,  UTH_MAXPRIO - i % UTH_MAXPRIO
                                        //2
                                        );
    }

    //uthread_setprio(thr[0], 6);

    for (i = 0; i < NUM_THREADS; i++)
    {
        char pbuffer[SBUFSZ];
        int	tmp, ret;

        uthread_join(thr[i], &tmp);
    
        sprintf(pbuffer, "joined with thread %i, exited %i.\n", thr[i], tmp);  
        ret = write(STDOUT_FILENO, pbuffer, strlen(pbuffer));
        if (ret < 0) 
        {
            perror("uthreads_test");
            return EXIT_FAILURE;
        }   

        /* 
        uthread_mtx_lock(&mtx);
        uthread_cond_signal(&cond);
        uthread_mtx_unlock(&mtx);
        */
        
    }
    printf("Main ends\n");
    uthread_exit(0);

    return 0;

}
コード例 #2
0
ファイル: condvar.c プロジェクト: stonebuddha/uthread
int main(int argc, char *argv[]) {
    uthread_t a[2];
    uthread_t b[2];

    uthread_mutex_init(&mut);
    uthread_cond_init(&c1);
    uthread_cond_init(&c2);

    uthread_create(&a[0], thread1, NULL);
    uthread_create(&a[1], thread1, NULL);
    uthread_create(&b[0], thread2, (void *) 0);
    uthread_create(&b[1], thread2, (void *) 1000);

    uthread_join(a[0], NULL);
    uthread_join(a[1], NULL);
    uthread_join(b[0], NULL);
    uthread_join(b[1], NULL);

    printf("%ld\n", cnt);

    return 0;
}
コード例 #3
0
ファイル: test.c プロジェクト: fangquan/Operating_System
int
main(int ac, char **av)
{
    int	i;


/*
    char buff[50];
    memset(buff,0,50);
    sprintf(buff, "helloworld\n");
    write(STDOUT_FILENO, buff, strlen(buff));
*/
    printf("hello\n");

    uthread_init();
    uthread_mtx_init(&mtx);
    uthread_cond_init(&cond);

    for (i = 0; i < NUM_THREADS; i++)
    {
        uthread_create(&thr[i], tester, i, NULL, 0);
    }
    uthread_setprio(thr[0], 2);


    for (i = 0; i < NUM_THREADS; i++)
    {
        char pbuffer[SBUFSZ];
        int	tmp, ret;

        uthread_join(thr[i], &tmp);
    
        sprintf(pbuffer, "joined with thread %i, exited %i.\n", thr[i], tmp);  
        ret = write(STDOUT_FILENO, pbuffer, strlen(pbuffer));
        if (ret < 0) 
        {
            perror("uthreads_test");
            return EXIT_FAILURE;
        }   

        uthread_mtx_lock(&mtx);
        uthread_cond_signal(&cond);
        uthread_mtx_unlock(&mtx);
    }

    uthread_exit(0);

    return 0;
}