⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 example1.cpp

📁 多任务操作系统控制的DOS环境下的实现的C语言源程序。 利用时间片的方式
💻 CPP
字号:
//--------------------------------------------------------------------------
//
//      EXAMPLE1.CPP: example program 1 for DOS coroutine library.
//      Copyright (c) J.English 1993.
//      Author's address: je@unix.brighton.ac.uk
//
//      Permission is granted to use copy and distribute the
//      information contained in this file provided that this
//      copyright notice is retained intact and that any software
//      or other document incorporating this file or parts thereof
//      makes the source code for the library of which this file
//      is a part freely available.
//
//--------------------------------------------------------------------------

#include <iostream.h>
#include "coroutine.h"

//--------------------------------------------------------------------------
//
//      Class Example1.
//
//      This class is a coroutine which displays a message three times
//      before terminating.
//
class Example1 : public Coroutine
{
  public:
    Example1 (int n)        { num = n; }

  protected:
    virtual void main ();   // code to be executed by coroutine

  private:
    int num;                // coroutine identification number
};

//--------------------------------------------------------------------------
//
//      Example1::main.
//
//      This is the code executed by each instance of class Example1.
//      It displays a startup message, executes a loop three times to
//      display a progress message, then finally displays a termination
//      message.
//
void Example1::main ()
{
    cout << "Coroutine E" << num << " started\n";

    for (int i = 1; i <= 3; i++)
    {   cout << "Coroutine E" << num << ", iteration " << i << "\n";
        pause ();
    }

    cout << "Coroutine E" << num << " finished\n";
}

//--------------------------------------------------------------------------
//
//      The main program.
//
//      This just demonstrates creating and executing a set of coroutines.
//      Three instances of class Example1 are created and started.  The main
//      program then terminates.  Termination of the main program will not
//      complete until the coroutines it declares have also completed.
//
void main ()
{
    Example1 e1 (1), e2 (2), e3 (3);

    if (!e1.run ())
        cout << "Couldn't start e1\n";
    if (!e2.run ())
        cout << "Couldn't start e2\n";
    if (!e3.run ())
        cout << "Couldn't start e3\n";

}   //--- destructors called here: wait for coroutines to finish, then exit

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -