首页 > 编程语言 > 详细

linux线程

时间:2015-03-31 00:45:11      阅读:276      评论:0      收藏:0      [点我收藏+]

 

 

 

#include <stdio.h>
#include <iostream>
#include "unistd.h"
#include "assert.h"
#include <stdlib.h>
#include "sys/wait.h"
#include <pthread.h>

pthread_t ntid;

void printids(std::string s){
    pid_t pid;
    pthread_t tid;

    pid = getpid();
    tid = pthread_self();
    printf("%s pid = %u tid = %u(hexadecimal) , (0x%x))\n", s.c_str(), (unsigned int)pid, (unsigned int)tid, (unsigned int)tid);
}

void* thr_callback(void* arg){
    sleep(20);
    printids("new thread:");

    return 0;
}


int main(int argc, char* argv[]){
    int err;
    err = pthread_create(&ntid, NULL, thr_callback, NULL);
    if(err != 0)
        printf("can‘t create thread, error code: %d\n", err);

    printids("main thread:");
    sleep(10);
    pthread_exit(0);
}

 

linux线程

原文:http://www.cnblogs.com/alazalazalaz/p/4379624.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!