2017-07-26 01:17:14 UTC
Suppose I start with my notion of object-oriented
programming and see how it fits with C(89 assumed).
I define an OOP situation as one involving software
objects communicating with one another by messages.
Each object will spend some processing time doing
things. There is no limit to how many messages may
be directed at it while it is doing some task. Hence
the object will have an input queue (or a more
complicated equivalent) and a message sent to it is
sent to its input queue. The object itself therefore
runs in a loop - read a message from its queue,
respond to the message, loop back for another message.
Now it seems likely that a time will come when the
object's queue is empty. So the object goes to sleep.
I need to specify the runtime environment in more
detail. I am assuming a multi-core processor and
mono-core objects. That is, while the object is
working it uses one particular core. Going to sleep
means passing that core back to the runtime
environment. When a message arrives for a sleeping
object the runtime returns a core - probably not the
same one it had before - to the object and lets it
Sending a message to another object is simple enough -
add the message to the other object's input queue.
But the runtime needs to know so it is better to post
the message to the runtime and let the runtime add it
to the queue. Of course if the object cannot proceed
without an expected reply to the message it starts
another input or goes to sleep.
I would hope that everybody on comp.lang.c is savvy
enough to see that everything I have envisioned can be
done in C - except that the runtime may need some help.
Is the situation really as simple as it seems to me?
PS: I assume external input can be implemented as a
semi-object - doesn't accept messages but generates
them according to what is happening outside the
computer. External output - like a screen - could be
the other kind of semi-object - never generates a m
essage but responds to them.