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

📄 ch3p2_threads.cpp

📁 游戏开发特殊技巧-special.effects.game.programming
💻 CPP
字号:
/*
#############################################################################

  Ch3p2_Threads.cpp - A simple multithreaded application that demonstrates
  the concept of multiple threading.

#############################################################################
*/

// Include Directives ///////////////////////////////////////////////////////
#include <windows.h>
#include <process.h>
#include <iostream.h>
#include <conio.h>

/****************************************************************************

 Walk: this is the entry point for our first thread.  The first thread will
 be running inside this function, at the same time the 2nd thread is in
 ChewGum.

 This thread walks.

 ****************************************************************************/
void Walk(void *args)
{
  while(1) {
    cout << "Walk   : putting one foot in front of the other..." << endl;
    Sleep(3000);
  }
}
/****************************************************************************

 ChewGum: The second thread entry point.  This thread chews gum.

 ****************************************************************************/
void ChewGum(void *args)
{
  while(1) {
    cout << "ChewGum: Chewing..." << endl;
    Sleep(2000);
  }
}
/****************************************************************************

 main: start of our application.

 ****************************************************************************/
int main(int argc, char* argv[])
{
  cout << "Ch3p2_Threads:  Press a key to exit." << endl;
  cout << "====================================" << endl;

  // start our two threads
	_beginthread(Walk, 0, NULL);
  _beginthread(ChewGum, 0, NULL);
  
  // at this point, we are running Walk and ChewGum at the same time.

  
  while (kbhit()) getch(); // clear any keys that may be in the buffer
  getch();
  
  // NOTE:  when the main() thread exits, all threads exit!
  return 0;
}

⌨️ 快捷键说明

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