C multi thread via pthread include pthread_create,pthread_join methods

#include <stdio.h>
#include <stdlib.h>
#include <uuid/uuid.h>
#include <string.h>
#include <pthread.h>

void *pMsg3(void *ptr);
void pthread8();

int main()
{
    pthread8();
    return 0;
}

void pthread8()
{
    pthread_t t1,t2;
    int ret1,ret2;
    char *msg1="Pthread_create(&t1,NULL,printMsg,(void*)msg1);";
    char *msg2="pthread_join(t1,NULL)";

    ret1=pthread_create(&t1,NULL,pMsg3,(void*)msg1);
    ret2=pthread_create(&t2,NULL,pMsg3,(void*)msg2);

    pthread_join(t1,NULL);
    pthread_join(t2,NULL);

    printf("Ret1=%dn",ret1);
    printf("Ret2=%dn",ret2);
}

void *pMsg3(void *ptr)
{
    char *mgs=(char*)ptr;
    printf("Str=%sn",mgs);
}

The 2 critical methods are thread creation and join as below.

pthread_create(&t1,NULL,MethodName,(void*)args);

pthread_join(t1,NULL);

 

Compile the c program via gcc must include -lpthread instructions;

gcc -g h1.c -o h1 -lpthread -luuid

Or

gcc h1.c -o h1 -lpthread -luuid

 

C multi thread via pthread include pthread_create,pthread_join methods

 

原文链接: https://www.cnblogs.com/Fred1987/p/15606148.html

欢迎关注

微信关注下方公众号,第一时间获取干货硬货;公众号内回复【pdf】免费获取数百本计算机经典书籍;

也有高质量的技术群,里面有嵌入式、搜广推等BAT大佬

    C multi thread via pthread include pthread_create,pthread_join methods

原创文章受到原创版权保护。转载请注明出处:https://www.ccppcoding.com/archives/401782

非原创文章文中已经注明原地址,如有侵权,联系删除

关注公众号【高性能架构探索】,第一时间获取最新文章

转载文章受原作者版权保护。转载请注明原作者出处!

(0)
上一篇 2023年4月19日 上午9:24
下一篇 2023年4月19日 上午9:25

相关推荐