Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR C

thread in c

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>  //Header file for sleep(). man 3 sleep for details.
#include <pthread.h>
  
// A normal C function that is executed as a thread 
// when its name is specified in pthread_create()
void *myThreadFun(void *vargp)
{
    sleep(1);
    printf("Printing GeeksQuiz from Thread 
");
    return NULL;
}
   
int main()
{
    pthread_t thread_id;
    printf("Before Thread
");
    pthread_create(&thread_id, NULL, myThreadFun, NULL);
    pthread_join(thread_id, NULL);
    printf("After Thread
");
    exit(0);
}
Source by www.geeksforgeeks.org #
 
PREVIOUS NEXT
Tagged: #thread
ADD COMMENT
Topic
Name
3+5 =