gm2
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Gm2] (no subject)


From: Izo
Subject: Re: [Gm2] (no subject)
Date: Fri, 03 Jan 2003 13:40:29 +0100
User-agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.0.1) Gecko/20020903

Abi Lover wrote:

Hi everyone,

I am new to this mailing list. I joined in order to ask a specific question. Is anyone here an expert on C/C++ as well as on Modula-2? My question requirtes a knowledge of both.

In Modula-2 there are a couple of language constructs which enable you set up several co-routines and make them run (or appear to run)concurrently: they are NEWPROCES and TRANSFER. They are also very useful to enable you to mimic some real life situations. Is there anything equivalent to this in C or C++?

No. This is purely M2 specialty and especially PIM2 which introduced the feature. It is not really useful in real situations since there is no scheduler and none of the stuff intended to resolve some process interactions and synchronization. But it was a good starter back in the '70 and '80 when M2 was designed as real programming tool step derived from the Pascal and as such it was widely used in embedded systems of that time. Normally you had to rewrite the underlying Process code to be really useful - I did some realtime extensions on HD6303 and MC68332 micros back at those times using rewritten and extended Process code.

All in all you can regard the Process module as the portable "multitask" level with all its limitations for demo and learning purposes.

As far as I know there didn't used to be, but GCC has added many new extensions to C and C++, and I don't know enough about them to know whether this is included. If it is not, how would you implement such a code in C or C++?


Well, gcc has not added any extensions to the C/C++. What happened is the POSIX extensions on threads in both kernel and user space which resulted on 2 major libc changes in past few years which resulted to non-functionality and non-portability of some code which is another story and has nothing to do with the C/C++ language specification which by all means is inferior to the M2's. On Unices the original multitasking enviroment is multiprocessing, while threading was added lately. So be encouraged at this point to use the POSIX (unistd.h : fork(), execwhatever(); pthread library) and WIN32 process and thread functions depending on the system where you use either GM2 or C++.



I have attached a small program which illustrates the use of this construct on Modula-2. This code was written using the old JPI TopSpeed Modula-2, running on DOS. It was written by our lecturer to illustrate this principle more than 10 years ago, when I was taught M2 at colege for the first time. It is a simple program which draws three boxes on the screen: in the first a star keeps moving back and forth, in the second the text, "Have a nice day," is constantly scrolling, and in the third you can enter text from the keyboard. All three events appear to be hapenning at the same time. Suppose you wanted to translate this code into C or C++, how would you do it?

The best way is to use XDS-C compiler which will have to use the native M2 RTS (RunTimeSystem).

The next way is to get you a source of the GM2 or the GardensPoint M2 Process module which are written in C or maybe even in assembly - thus you will get the insight into the real M2 Process happening.



Thanks for your help

You're welcome !

I.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]