Untitled

mail@pastecode.io avatar
unknown
plain_text
2 years ago
2.8 kB
2
Indexable
Never
void test1(){
    /* 
        passengers 1-4:
        2 LR at time 0 
        2 RL at time 1
        result : first 2 LR cross then 2 RL cross

        passengers 5-8:
        2 RL at time 4
        2 LR at time 5
        result : first 2 RL cross then 2 LR cross        
    */
    vip_time=2; 
    pthread_t threads[8];
    // test LR first
    int id=0;
    pthread_create(&threads[id], NULL, vip_LR, (void*) new Passenger(id+1));
    id++;
    pthread_create(&threads[id], NULL, vip_LR, (void*) new Passenger(id+1));
    sleep(1);
    id++;
    pthread_create(&threads[id], NULL, vip_RL, (void*) new Passenger(id+1));
    id++;
    pthread_create(&threads[id], NULL, vip_RL, (void*) new Passenger(id+1));

    sleep(3);
    
    // test RL first
    id++;
    pthread_create(&threads[id], NULL, vip_RL, (void*) new Passenger(id+1));
    id++;
    pthread_create(&threads[id], NULL, vip_RL, (void*) new Passenger(id+1));
    sleep(1);
    id++;
    pthread_create(&threads[id], NULL, vip_LR, (void*) new Passenger(id+1));
    id++;
    pthread_create(&threads[id], NULL, vip_LR, (void*) new Passenger(id+1));
}

void test2(){
    /* 
        test LR priority:
        1 RL at time 0
        1 RL at time 1
        2 LR at time 2
        2 RL at time 3
        result : first 1,2 RL; 3,4 LR, 5,6 RL
    */

    vip_time=3; 
    pthread_t threads[6];
    // test LR first
    int id=0;
    pthread_create(&threads[id], NULL, vip_RL, (void*) new Passenger(id+1));
    id++;
    sleep(2);
    pthread_create(&threads[id], NULL, vip_RL, (void*) new Passenger(id+1));
    sleep(1);
    id++;
    pthread_create(&threads[id], NULL, vip_LR, (void*) new Passenger(id+1));
    id++;
    pthread_create(&threads[id], NULL, vip_LR, (void*) new Passenger(id+1));
    sleep(1);
    id++;
    pthread_create(&threads[id], NULL, vip_RL, (void*) new Passenger(id+1));
    id++;
    pthread_create(&threads[id], NULL, vip_RL, (void*) new Passenger(id+1));
}

void test3(){
    /* 
        test RL priority:
        1 LR at time 0
        1 LR at time 1
        2 RL at time 2
        2 LR at time 3
        result : first 1,2,5,6 LR, 3,4 RL
    */

    vip_time=3; 
    pthread_t threads[6];
    // test LR first
    int id=0;
    pthread_create(&threads[id], NULL, vip_LR, (void*) new Passenger(id+1));
    id++;
    sleep(2);
    pthread_create(&threads[id], NULL, vip_LR, (void*) new Passenger(id+1));
    sleep(1);
    id++;
    pthread_create(&threads[id], NULL, vip_RL, (void*) new Passenger(id+1));
    id++;
    pthread_create(&threads[id], NULL, vip_RL, (void*) new Passenger(id+1));
    sleep(1);
    id++;
    pthread_create(&threads[id], NULL, vip_LR, (void*) new Passenger(id+1));
    id++;
    pthread_create(&threads[id], NULL, vip_LR, (void*) new Passenger(id+1));
}