声明同这篇文章,以下是代吗
#include <cmnheader.h>
#define THREADGROUPSIZE 5
void *theThread(void *param)
{
printf("Thread %.8x %.8x: Entered\n", getpid());
printf("Thread %.8x %.8x: Working\n", getpid());
Sleep(15);
printf("Thread %.8x %.8x: Done with work\n", getpid());
return NULL;
}
int main(int argc, char **argv)
{
pthread_t thread[THREADGROUPSIZE];
void *status[THREADGROUPSIZE];
int i;
int rc = 0;
printf("Enter Testcase - %s\n", argv[0]);
printf("Create/start some worker threads\n");
for (i = 0; i < THREADGROUPSIZE; ++i)
{
rc = pthread_create(&thread[i], NULL, theThread, NULL);
checkResults("pthread_create()\n", rc);
}
printf("Wait for worker threads to complete, release their resources\n");
for (i = 0; i < THREADGROUPSIZE; ++i)
{
rc = pthread_join(thread[i], &status[i]);
checkResults("pthread_join()\n", rc);
}
printf("Check all thread's results\n");
for (i = 0; i < THREADGROUPSIZE; ++i)
{
if (status[i] != NULL)
{
printf("Unexpected thread status\n");
}
}
printf("Main completed\n");
system("pause");
return 0;
}