Q.16:What will be the output of the following C code? #include void main() { int x = 4, y, z; y =-
-X, Z = X--; printf("%d%d%d", x, y, z); }
a) O 2 34
b) 323
c) O 233
d) 0 322
Answers
Answer:
pthread_mutex_t mut;
pthread_t thread[2];
int threads_joined = 0;
char * t1 = "Thread 1";
char * t2 = "Thread 2";
/*********************************************************************/
/* thread_cleanup: condition handler to clean up threads */
/*********************************************************************/
void thread_cleanup(_FEEDBACK *cond,_INT4 *input_token,
_INT4 *result, _FEEDBACK *new_cond) {
/* values for handling the conditions */
#define percolate 20
printf(">>> Thread_CleanUp: Msg # is %d\n",cond->tok_msgno);
if (!threads_joined) {
printf(">>> Thread_CleanUp: Unlocking mutex\n");
pthread_mutex_unlock(&mut);
printf(">>> Thread_CleanUp: Joining threads\n");
if (pthread_join(thread[0],NULL) == -1 )
perror("Join of Thread #1 failed");
if (pthread_join(thread[1],NULL) == -1 )
perror("Join of Thread #2 failed");
threads_joined = 1;
}
*result = percolate;
printf(">>> Thread_CleanUp: Percolating condition\n");
}
/*********************************************************************/
/* thread_func: Invoked via pthread_create. */
/*********************************************************************/
void *thread_func(void *parm)
{
printf(">>> Thread_func: %s locking mutex\n",parm);
pthread_mutex_lock(&mut);
pthread_mutex_unlock(&mut);
printf(">>> Thread_func: %s exitting\n",parm);
pthread_exit(NULL);
}