예제 #1
0
int XXp3(char *arg)
{
    char buffer[100];
    int i = 0, result, count;

    USLOSS_Console("\nXXp3(): started\n");

    count = 0;
    while ( (result = MboxCondReceive(mbox_id, buffer, 100)) >= 0 ) {
        USLOSS_Console("XXp3(): conditionally received message #%d ", i);
        USLOSS_Console("from mailbox %d\n", mbox_id);
        USLOSS_Console("        message = `%s'\n", buffer);
        count++;
    }
    USLOSS_Console("XXp3(): After loop, result is negative; result = %d\n",
                   result);
    USLOSS_Console("XXp3(): received %d hello messages from mailbox %d\n",
                   count, mbox_id);

    MboxSend(pause_mbox, NULL, 0); // should release XXp1

    count = 0;
    while ( (result = MboxCondReceive(mbox_id, buffer, 100)) >= 0 ) {
        USLOSS_Console("XXp3(): conditionally received message #%d ", i);
        USLOSS_Console("from mailbox %d\n", mbox_id);
        USLOSS_Console("        message = `%s', result = %d\n", buffer, result);
        count++;
    }
    USLOSS_Console("XXp3(): After loop, result is negative; result = %d\n",
                   result);
    USLOSS_Console("XXp3(): received %d good-bye messages from mailbox %d\n",
                   count, mbox_id);

    quit(-4);
    return 0;
} /* XXp3 */
예제 #2
0
파일: test20.c 프로젝트: dkothari777/CSC452
int start2(char *arg)
{
    int kid_status, kidpid, pausepid;
    char buffer[20];
    int result;

    USLOSS_Console("start2(): started\n");
    mbox_id  = MboxCreate(0, 50);
    USLOSS_Console("\nstart2(): MboxCreate returned id = %d\n", mbox_id);

    kidpid   = fork1("XXp2a", XXp2, "XXp2a", 2 * USLOSS_MIN_STACK, 3);
    kidpid   = fork1("XXp2b", XXp2, "XXp2b", 2 * USLOSS_MIN_STACK, 3);
    kidpid   = fork1("XXp2c", XXp2, "XXp2c", 2 * USLOSS_MIN_STACK, 3);
    pausepid = fork1("XXp4",  XXp4, "XXp4",  2 * USLOSS_MIN_STACK, 3);
    kidpid = join(&kid_status);
    if (kidpid != pausepid)
        USLOSS_Console("\n***Test Failed*** -- join with pausepid failed!\n\n");

    kidpid   = fork1("XXp3",  XXp3, NULL,    2 * USLOSS_MIN_STACK, 2);

    kidpid = join(&kid_status);
    USLOSS_Console("\nstart2(): joined with kid %d, status = %d\n",
                   kidpid, kid_status);

    kidpid = join(&kid_status);
    USLOSS_Console("\nstart2(): joined with kid %d, status = %d\n",
                   kidpid, kid_status);

    kidpid = join(&kid_status);
    USLOSS_Console("\nstart2(): joined with kid %d, status = %d\n",
                   kidpid, kid_status);

    kidpid = join(&kid_status);
    USLOSS_Console("\nstart2(): joined with kid %d, status = %d\n",
                   kidpid, kid_status);

    result = MboxCondReceive(mbox_id, buffer, 20);

    if(result == -1)
        USLOSS_Console("failed to recv from released mailbox ... success\n");
    else
        USLOSS_Console("test failed result = %d\n",result);
    quit(0);
    return 0; /* so gcc will not complain about its absence... */
} /* start2 */