C question: message passing

Programming, for all ages and all languages.
Post Reply
conlonloi
Posts: 4
Joined: Sun Sep 25, 2011 11:52 pm

C question: message passing

Post by conlonloi »

Hi,
I am trying to write a few system call for message passing
the saveMsg system call takes parameters of message ID, length and content
so Im trying to use a struct Msg that contain long ID, long length, and char msg
so where should I save the data for all of the messages I saved so that the retrieveMsg system call can get the content of the message by ID?

thanks
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

Re: C question: message passing

Post by Combuster »

Do not switch browser tabs or windows, do not grab a book. Name at least 6 data structures. List their operations and how well they perform. Explain for each unique operation why it is relevant for your task or not.

Did that solve your problem? (If you could not answer those questions at all or had to peek, please go read the forum rules)
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
User avatar
bluemoon
Member
Member
Posts: 1761
Joined: Wed Dec 01, 2010 3:41 am
Location: Hong Kong

Re: C question: message passing

Post by bluemoon »

Since this is an OS development forum and you mentioned system calls; I assume your question is non-trivial. Can you state more on your requirement?

For example, at what level the message passing interface works?
Within an multi-threaded application or inter-process communication?
Support message priority?
Should it affect scheduling?
Does it enforce a fixed size payload or is it dynamic, and have a certain size limit?

It can actually get quite complicated when you integrate with scheduler and memory manager; on the other hand, it is very simple to implement a plain message queue as a library function.
Casm
Member
Member
Posts: 221
Joined: Sun Oct 17, 2010 2:21 pm
Location: United Kingdom

Re: C question: message passing

Post by Casm »

conlonloi wrote:Hi,
I am trying to write a few system call for message passing
the saveMsg system call takes parameters of message ID, length and content
so Im trying to use a struct Msg that contain long ID, long length, and char msg
so where should I save the data for all of the messages I saved so that the retrieveMsg system call can get the content of the message by ID?

thanks
Build a linked list of saved messages, sorted numerically if necessary. Allocate memory for them one at a time, ten at a time, or whatever seems reasonable (assuming you have a memory manager, which I think should be one of the first things you write).
nulik
Member
Member
Posts: 46
Joined: Thu Oct 20, 2011 2:07 pm

Re: C question: message passing

Post by nulik »

conlonloi wrote:Hi,
I am trying to write a few system call for message passing
the saveMsg system call takes parameters of message ID, length and content
so Im trying to use a struct Msg that contain long ID, long length, and char msg
so where should I save the data for all of the messages I saved so that the retrieveMsg system call can get the content of the message by ID?

thanks
I don't know what exactly you are coding, but if you need brief intro about messages check this:
http://wiki.osdev.org/Message_Passing
and if you need an in deep study check out these:
"User-Level Interprocess Communication for Shared Memory Multiprocessors (1991)"
http://citeseer.ist.psu.edu/viewdoc/sum ... .1.17.1382
it is old but frequently cited by many OS developers
here is another one:
http://www.barrelfish.org/barrelfish_sosp09.pdf
Now, about this one, it is sponsored by Microsoft, and developed by a lot of gurus, but when they released the OS code it was slow , and (i think) it is because they don't use shared memory but pass large messages.

You could also search for keywords adding 'pdf' to your query and it will find a lot of messaging implementations of other people, some of them state of the art.
Post Reply