声明:此系列代码参考了“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 Universe and Everything");
printf("Create/start a thread with parameters\n");

这篇博客详细介绍了在Windows系统中如何使用pthread库创建和管理多线程,特别提到了需要注意引用Windows.h中的Sleep函数,以实现线程间的同步和延时操作。
最低0.47元/天 解锁文章
1119

被折叠的 条评论
为什么被折叠?



