// MUD Programming
// Ron Penton
// (C)2003
// Demo03-01.cpp - Basic Threading
// This program runs three threads, one which manages two child threads,
// and two child threads that alternate printing a letter.
#include <iostream>
using namespace std;
#include "ThreadLib/ThreadLib.h"
void PrintThread( void* data )
{
// convert the data passed in into a character.
char c = (int)data;
for( int i = 0; i < 10000; i++ )
{
cout << c;
cout.flush();
}
}
int main()
{
ThreadLib::ThreadID a, b;
a = ThreadLib::Create( PrintThread, (void*)'a' );
b = ThreadLib::Create( PrintThread, (void*)'b' );
ThreadLib::WaitForFinish( b );
ThreadLib::WaitForFinish( a );
char c;
cin >> c;
return 0;
}
MUD游戏编程 示例3.1基本线程
最新推荐文章于 2026-05-07 07:20:51 发布
本文展示了一个简单的多线程程序示例,该程序创建了两个子线程交替打印字符'a'和'b'各10000次。通过使用ThreadLib库实现线程管理,演示了如何创建和等待线程完成。

2927

被折叠的 条评论
为什么被折叠?



