声明:此系列代码参考了“Professional Group Tec. Doc.07121901 Author-万一飞”的教程。
下述cmnheader.h的内容详见这里(第二段代码),另注意sleep()函数在Windows下应当引用WIndows.h的Sleep() 注意此处的"S"为大写字母
#include "cmnheader.h"
typedef struct
{
int threadParm1;
char threadParm2[124];
} threadParm_t;
void *theThread(void *param)
{
pid_t tid = getpid();
threadParm_t *p = (threadParm_t *)param;
printf("Thread ID %.8x, Parameters: %d is the answer to \n\"%s\"\n", tid, p->threadParm1, p->threadParm2);
return NULL;
}
int main(int argc, char **argv)
{
pthread_t thread;
int rc = 0;
threadParm_t *threadParm;
printf("Enter Testcase - %s\n", argv[0]);
threadParm = (threadParm_t *)malloc(sizeof(threadParm));
threadParm->threadParm1 = 42;
strcpy(threadParm->threadParm2, "Life, the Un