Beispiel #1
0
int main(void *args)
{
        int pid1, pid2;
        int r;
        int arg = 0;

        (void)args;
        assert(getprio(getpid()) == 128);
        pid1 = start("busy1", 4000, 64, (void *) arg);
        assert(pid1 > 0);
        pid2 = start("busy2", 4000, 64, (void *) pid1);
        assert(pid2 > 0);
        printf("1 -");
        r = chprio(getpid(), 32);
        assert(r == 128);
        printf(" - 2");
        r = kill(pid1);
        assert(r == 0);
        assert(waitpid(pid1, 0) == pid1);
        r = kill(pid2);
        assert(r < 0); /* kill d'un processus zombie */
        assert(waitpid(pid2, 0) == pid2);
        printf(" 3");
        r = chprio(getpid(), 128);
        assert(r == 32);
        printf(" 4.\n");

        return 0;
}
procchprio(char c) {
    int i;
    int count = 0;
    while (count++ < LOOP/6) {
        kprintf("%c", c);
        for (i = 0; i < 10000000; i++);
    }
    chprio(prB,200);
    kprintf("X");
    while (count++ < LOOP) {
        kprintf("%c", c);
        for (i = 0; i < 10000000; i++);
    }
}
Beispiel #3
0
// Priority Inheritance chprio test
void pinh_chprio_test() {
    int lck;
    int rd1;
    int wr1, wr2;
    int lp;

    kprintf("\nBasic Priority chprio Test\n"
    "Once looper process is started readers/writers will be\n"
    "starved until chprio() is used to change prio of reader C\n"
    "(currently waiting on lock) to 30\n"
    " lock acquisition is:\n" 
    "writer A\n"
    "writer B\n"
    "reader C\n");
    lck = lcreate();

    // Create a process that is always ready to run at priority 15
    lp = create(looper, 2000, 15, "looper", 0, NULL); 

    wr1 = create(writer, 2000, 10, "writer", 4, "writer A p10 l20", lck, 20, 5);
    wr2 = create(writer, 2000, 11, "writer", 4, "writer B p11 l30", lck, 30, 2);
    rd1 = create(reader, 2000, 12, "reader", 4, "reader C p12 l20", lck, 20, 1);

    kprintf("-start writer A (pprio 10, lprio 20), then sleep 1s.\n");
    resume(wr1);
    sleep(1);

    kprintf("-start writer B (pprio 11, lprio 30), then sleep 1s.\n");
    resume(wr2);
    sleep(1);

    kprintf("-start reader C (pprio 12, lprio 20), then sleep 1s.\n");
    resume(rd1);
    sleep(1);

    // This will guarantee that writer B will never get chosen unless
    // we boost its priority. 
    kprintf("-start looper process (pprio 15), then sleep 8s.\n");
    resume(lp);
    sleep(8);

    //chprio 
    kprintf("-chprio of reader C to 30 --> All readers/writers will have effective priority 30.\n");
    chprio(rd1, 30);
    
    sleep (10);
    kprintf ("Test finished, verify readers/writers were hung until chprio!\n");
}