C++学习之旅 - 线程

#include <iostream>
#include <thread>
#include <ctime>

using namespace std;

void Delay(int time) {
    
    
	clock_t   now = clock();

	while (clock() - now < time);
}

void showInfo() {
    
    
	int i = 0;
	for (;;) {
    
    
		cout << i++ << endl;
		Delay(2 * 1000);//2s
		
	}
}

int main() {
    
    
	thread my_thread(&showInfo);
	my_thread.join();
	return 0;
}

猜你喜欢

转载自blog.csdn.net/yasinawolaopo/article/details/131382052