Linux下多线程:
#include <iostream>
#include <pthread.h>
#include <unistd.h>
#include <stdlib.h>
using namespace std;
void* sayHelloZhongguo(void*)
{
for (unsigned int i = 0; i < 100; i++)
{
sleep(1);
cout << i << endl;
}
pthread_exit(NULL);
}
void* sayHelloUSA(void*)
{
for (unsigned int i = 9900; i < 10000; i++)
{
sleep(1);
cout << i << endl;
}
pthread_exit(NULL);
}
int main()
{
pthread_t i_pthread[2];
int i_res;
i_res = pthread_create(&i_pthread[0], NULL, sayHelloZhongguo, NULL);
<