linux c-process creation pass value


#include <pthread.h>
#include <stdio.h>
#include <unistd.h>
#include <iostream>
using namespace std;

typedef struct thread_info {    /* Used as argument to thread_start() */
    pthread_t thread_id;        /* ID returned by pthread_create() */
    int       thread_num;       /* Application-defined thread # */
    char* argv_string;      /* From command-line argument */
}INFO_T;
void* start_routine (void* arg) 
{
    //cout << ((INFO_T*)arg)->thread_num << endl;
    cout << *(int *)arg << endl;
    cout << "new thread" << endl;

}
int main() 
{
    //INFO_T* tinfo;
    //tinfo->thread_num = 5;
    int num = 5;
    pthread_t tid;
    int ret=pthread_create(&tid, NULL,start_routine,&num);
    if (ret!=0) 
    {
    
        perror("pthread:");
    
    }
    cout << "hello" << endl;
    sleep(1);


    return 0;
}

Guess you like

Origin blog.csdn.net/z15005953031/article/details/113915206