list5-9.cpp

来自「这是c++编程方面的名著的例子代码」· C++ 代码 · 共 59 行

CPP
59
字号
// Listing 5-9
// This program demonstrates the use of
// parameter passing during the process
// of thread creation

#include <iostream.h>
#include <process.h>
#include <rational.h>
#define INCL_DOSPROCESS
#include <os2.h>

rational M(1,2);

void threadA(void *X)
{
    rational *Q;
    Q = (rational *) X;
    rational Z(3,4);
    M = *Q + Z;
    cout << "thread A"  << endl;
    cout << *Q << " + " << Z <<  " = " << M << endl << endl;
}

void threadB(void *X)
{
   rational *N;
   rational Q(1,1);
   N = (rational *) X;
   Q = M + *N;
   cout << "thread B" << endl;
   cout << M << " + " << *N << " = " << Q << endl << endl;   
}



void main(void)
{
    unsigned long ThreadA;
    unsigned long ThreadB;
    rational *N;
    N = new rational(5,3);
    ThreadA = _beginthread(threadA,4096,N);
    ThreadB = _beginthread(threadB,4096,N);
    DosWaitThread(&ThreadA,DCWW_WAIT);
    DosWaitThread(&ThreadB,DCWW_WAIT);
    delete N;
}
    










⌨️ 快捷键说明

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