码迷,mamicode.com
首页 > 编程语言 > 详细

linux线程

时间:2015-03-31 00:46:35      阅读:126      评论: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
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!