Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR CPP

pthread c++ example with output

// thread01.c
#include <pthread.h>
#include <stdio.h>
#include <stdlib.h>

#define N 5

void *worker_thread(void *arg)
{
        printf("This is worker_thread #%ld
", (long)arg);
        pthread_exit(NULL);
}

int main()
{
        pthread_t my_thread[N];

        long id;
        for(id = 1; id <= N; id++) {
                int ret =  pthread_create(&my;_thread[id], NULL, &worker;_thread, (void*)id);
                if(ret != 0) {
                        printf("Error: pthread_create() failed
");
                        exit(EXIT_FAILURE);
                }
        }

        pthread_exit(NULL);
}
Source by www.bogotobogo.com #
 
PREVIOUS NEXT
Tagged: #pthread #output
ADD COMMENT
Topic
Name
2+3 =