some problems of hw4

9 views
Skip to first unread message

Weiwei Gong

unread,
Apr 21, 2010, 1:29:51 AM4/21/10
to cs644s...@googlegroups.com
Hi all,

     I got some problems while doing hw4.

1) The 1st one is to receive message in my ureceive() function. In my ureceive() function, I use polling method to check status flag to see whether there is a message waiting to be read, if so, get the message and return, else wait.

     I also use semaphore around the code checking status and changing flag.

     But the problem is: after main() send msg to 1st process(I print out the message after writing it to data struct in usend()), ureceive() fails to read the updated flag value and still blocks. Here is part of my code,

    while(1) {
        wait(mutex);
        if(flag == 1){
            result = msg;
            flag = 0;
            signal(mutex);
            break;
        }
        signal(mutex);
        sleep(n);
    }

     
      I guess maybe my method is wrong. I did this implementation based on two assumptions: 1. we are not allowed to use privileged function such as resched() and ready(); 2) there is no shared memory on Xinu because I remember professor mentioned it only has one V.A in class. Do I remember correctly? Could you give me some hint please? I have spent several hrs weekend and today on this problem... :(


2) The 2nd problem is about preceive(). In main() of my timeout.c, when "success" wins, I can't see the received message using preceive(). Here are part of my code.

in main():
        recmsg = (char *)preceive(port);
        printf("Psend process wins, msg = %s.\n", recmsg);

in "success":
        char *buf;
        psend(port, buf);

      I am so confused since this is just two simple call borrowed from porttest example. Please give me some hints too.



 
Thank you very much!


Weiwei

Betty O'Neil

unread,
Apr 21, 2010, 10:33:50 AM4/21/10
to cs644s...@googlegroups.com
Please don't post code to the Google group! You can send it to me
directly. Or ask me to look at it in your hw4 dir. That is usually
the better way, unless it is a very local problem.

Xinu has plenty of shared memory! All external variables are shared.
So the master array you need to set up for messages is shared.

The idea in receive is to block, not poll. You can block on a semaphore.
For the user-level system, you need one semaphore for the whole system for
mutex, *plus* one semaphore per active receiver (or active process slot)
for blocking.

For the kernel code, just replace the mutex sem with disable/restore.

Hope this helps. Let me know if you need more help.
> --
> Subscription settings: http://groups.google.com/group/cs644s10_umb/subscribe?hl=en
>
Reply all
Reply to author
Forward
0 new messages