Path: utzoo!attcan!uunet!mcvax!unido!laura!exunido!bause From: bause@exunido.uucp (Falko Bause) Newsgroups: comp.lang.c++ Subject: Coroutines in C++ Message-ID: <657@laura.UUCP> Date: 18 Oct 88 09:53:27 GMT Sender: root@laura.UUCP Reply-To: bause@exunido.UUCP (Falko Bause) Organization: University of Dortmund, W-Germany Lines: 86 COROUTINE CONCEPT IN C++ ======================== Thanks for all the mails I got. Most of the mails refer to task.h where procedures for event scheduling simulation are declared (is that correct? ; the documentation for task.h isn't available to me at the moment). I also got one message by thomas%spline.uucp@utah-gr.UUCP (Spencer W. Thomas) (Newsgroups: comp.unix.wizards Subject: Re: A very interesting problem -- multiprocessing) with C-source code implementing the SIMULA-like procedures detchach and resume. It is a not fully tested version running on PDP-11 architecture and not portable. To my mind the procedures in task.h are not very suited to a process interaction style of simulation, which is, I think, the best style for simulation. On the other hand it is always possible to implement process interaction in languages which don't support the use of coroutines. I've done this in PASCAL some years ago. E.g. take the following code which represents the process of a "worker": void worker(); { while (1) { goto_work(); hold(4); // time scale e.g. in hours goto_lunch(); hold(0.5); go_back_working(); hold(4); go_home(); passivate(); // wait until ringing bell activates worker } } This process can be implemented in nearly every language by storing the entry point into the procedure for the next "resume". void worker(); { switch (status_of_worker:) // indicating the present status of the worker // it therefore represents implicitly the entry // points of the procedure { case at_home: status_of_worker = before_lunch; goto_work(); hold(4); break; case before_lunch: status_of_worker = lunch; goto_lunch(); hold(0.5); break; case lunch: status_of_worker = after_lunch; go_back_working(); hold(4); break; case after_lunch: status_of_worker = at_home; passivate(); break; } } This function is called by other "process procedures" activating the worker. This example shows that process interaction can be implemented in every language leaving the handling of the entry points to the programmer. My first question (if there is a coroutine concept in C++) therefore asks for a possibilty to write the procedures for processes in a SIMULA-like style like the first version of worker(). Is that possible in C++? Falko