Examveda
Examveda

Which one of the following string will print first by this program?
#include<stdio.h>
#include<pthread.h>
#include<semaphore.h>
 
sem_t st;
void *fun_t(void *arg);
void *fun_t(void *arg)
{
    printf("Linux\n");
    sem_post(&st);
    pthread_exit("Bye"); 
}
int main()
{
    pthread_t pt;
    void *res_t;
    if(pthread_create(&pt,NULL,fun_t,NULL) == -1)
        perror("pthread_create");
    if(sem_init(&st,0,0) != 0)
        perror("sem_init");
    if(sem_wait(&st) != 0)
        perror("sem_wait");
    printf("Example\n");
    if(pthread_join(pt,&res_t) == -1)
        perror("pthread_join");
    if(sem_destroy(&st) != 0)
        perror("sem_destroy");
    return 0;
}

A. Linux

B. Example

C. Can not be predicted

D. None of the mentioned

Answer: Option A


This Question Belongs to Computer Science >> Linux

Join The Discussion

Related Questions on Linux