Previous Year Questions: Thread | Operating System - Computer Science Engineering (CSE) PDF Download

Q1: Which of the following statements about threads is/are TRUE?  (2024 SET 1)
(a) Threads can only be implemented in kernel space
(b) Each thread has its own file descriptor table for open files
(c) All the threads belonging to a process share a common stack
(d) Threads belonging to a process are by default not protected from each other
Ans: (d)
Sol: 
A) User Level Thread are also present which are created by user, which are not implemented in Kernel Space. [ FALSE ]
B) Each Process has File Descriptor , and thread belonging to that process share among themselves. [ FALSE]
C) All the threads belong to process share Heap Memory , each thread has its own stack . [ FALSE ]
D) Yes, By default the threads are not protected from each other , they might end up using the false results for the execution. [ TRUE ]

Q2: Which one or more of the following need to be saved on a context switch from one thread (T1) of a process to another thread (T2) of the same process?  (2023)
(a) Page table base register
(b) Stack pointer
(c) Program counter
(d) General purpose registers
Ans: 
(b, c, d)
Sol:
page table base register: This register holds the base address of the page table for the currently executing thread. Since all the threads of a process share the same page table, this register needs needs not be saved.
Stack pointer: This register points to the top of the stack for the currently executing thread. Since each thread has its own stack, the stack pointer needs to be saved and restored on a context switch to ensure that the new thread uses the correct stack.
Program counter: This register contains the address of the next instruction to be executed by the currently executing thread. To resume execution of the new thread, the saved program counter needs to be loaded into the program counter register.
General purpose registers: These registers are used to store temporary data and intermediate results during the execution of a thread. Since the state of these registers can be different for each thread, they need to be saved and restored on a context switch.
So, the Stack pointer, Program counter, and General purpose registers must be saved before a context switch between threads (or between processes) to ensure correct execution of the program.
Answer: B, C, D

Q3: Consider the following multi-threaded code segment (in a mix of C and pseudo-code), invoked by two processes P1 and P2, and each of the processes spawns two threads T1 and T2:  (2021 SET 1)
Previous Year Questions: Thread | Operating System - Computer Science Engineering (CSE)

Which of the following statement(s) is/are correct?
[MSQ]
(a) Both P1 and P2 will print the value of x as 2.
(b) At least of P1 and P2 will print the value of x as 4.
(c) At least one of the threads will print the value of y as 2.
(d) Both T1 and T2, in both the processes, will print the value of y as 1.
Ans: 
(a, d)
Sol:
Each process has its own address space.
1. P1:
Two threads T11, T12 are created in main.
Both execute foo function and threads don’t wait for each other. Due to explicit locking mechanism here mutual exclusion is there and hence no race condition inside foo().
 y being thread local, both the threads will print the value of y  as 1.
Due to the wait in main, the print(x) will happen only after both the threads finish. So, x will have become 2.
PS: Even if x was not assigned 0 explicitly in C all global and static variables are initialized to 0 value.
2. P2:
Same thing happens here as P1 this is a different process. For sharing data among different processes mechanisms like shared memory, files, sockets etc must be used.
So, the correct answer here is A and D.

Q4: Which of the following is/are shared by all the threads in a process ?  (2017 SET 2)
I. Program counter
II. Stack
III. Address space
IV. Registers
(a) I and II only
(b) III only
(c) IV only
(d) III and IV only
Ans:
(b)
Sol: 
Thread is light weight process, and every thread have its own, stack, register, and PC (one of the register in CPU contain address of next instruction to be executed), so only address space that is shared by all thread for a single process.
So, option (B) is correct answer.

Q5: Threads of a process share  (2017 SET 1)
(a) global variable but not heap.
(b) heap but not global variables.
(c) neither global variables nor heap.
(d) Both heap and global variables.
Ans: 
(d)
Sol: 
A thread shares with other threads a process’s (to which it belongs to) :

  •  Code section
  • Data section (static + heap)
  • Address Space
  • Permissions
  • Other resources (e.g. files)

Therefore, (D) is the answer.

Q6:Which one of the following is FALSE?  (2014 SET 1)
(a) User level threads are not scheduled by the kernel
(b) When a user level thread is blocked, all other threads of its process are blocked.
(c) Context switching between user level threads is faster than context switching between kernel level threads.
(d) Kernel level threads cannot share the code segment
Ans: 
(d)
Sol: 
(D) is the answer. Threads can share the Code segments. They have only separate Registers and stack.
User level threads are scheduled by the thread library and kernel knows nothing about it. So, A is TRUE.
When a user level thread is blocked, all other threads of its process are blocked. So, B is TRUE. (With a multi-threaded kernel, user level threads can make non-blocking system calls without getting blocked. But in this option, it is explicitly said 'a thread is blocked'.)
Context switching between user level threads is faster as they actually have no context-switch- nothing is saved and restored while for kernel level thread, Registers, PC and SP must be saved and restored. So, C also TRUE. 


Q7: A thread is usually defined as a 'light weight process' because an operating system (OS) maintains smaller data structures for a thread than for a process. In relation to this, which of the followings is TRUE?  (2011)
(a) On per-thread basis, the OS maintains only CPU register state
(b) The OS does not maintain a separate stack for each thread
(c) On per-thread basis, the OS does not maintain virtual memory state
(d) On per thread basis, the OS maintains only scheduling and accounting information
Ans:
(c)
Sol: 
Answer to this question is (C).
Many of you would not agree at first So here I explain it how.
OS , on per thread basis, maintains ONLY TWO things : CPU Register state and Stack space. It does not maintain anything else for individual thread. Code segment and Global variables are shared. Even TLB and Page Tables are also shared since they belong to same process.
A. option (A) would have been correct if 'ONLY' word were not there. It NOT only maintains register state BUT stack space also.
B. is obviously FALSE
C. is TRUE as it says that OS does not maintain VIRTUAL Memory state for individual thread which isTRUE
D. This is also FALSE.


Q8: Let the time taken to switch between user and kernel modes of execution be t1 while the time taken to switch between two processes be t2. Which of the following is TRUE?  (2011)
(a) t 1 > t 2
(b) t 1 = t 2 
(c) t 1 < t 2
(d) Nothing can be said about the relation between t1 and t2
Ans:
(c)
Sol: Time taken to switch two processes is very large as compared to time taken to switch between kernel and user mode of execution because :
When you switch processes, you have to do a context switch, save the PCB of previous process (note that the PCB of a process in Linux has over 95entries), then save registers and then load the PCB of new process and load its registers etc.
When you switch between kernel and user mode of execution, OS has to just change a single bit at hardware level which is very fast operation.
So, answer is: (C).

Q9: Consider the following statements about user level threads and kernel level threads. Which one of the following statements is FALSE?  (2007)
(a) Context switch time is longer for kernel level threads than for user level threads.
(b) User level threads do not need any hardware support.
(c) Related kernel level threads can be scheduled on different processors in a multi-processor system.
(d) Blocking one kernel level thread blocks all related threads.
Ans: 
(d)
Sol: 

A. Context switch time is longer for kernel level threads than for user level threads. − This is True, as Kernel level threads are managed by OS and Kernel maintains lot of data structures. There are many overheads involved in Kernel level thread management, which are not present in User level thread management !
B. User level threads do not need any hardware support.− This is true, as User level threads are implemented by Libraries programmable, Kernel does not sees them.
C. Related kernel level threads can be scheduled on different processors in a multi-processor system.− This is true.
D. Blocking one kernel level thread blocks all related threads. − This is false. If it had been user Level threads this would have been true, (In One to one, or many to one model !) Kernel level threads are independent.

The document Previous Year Questions: Thread | Operating System - Computer Science Engineering (CSE) is a part of the Computer Science Engineering (CSE) Course Operating System.
All you need of Computer Science Engineering (CSE) at this link: Computer Science Engineering (CSE)
10 videos|99 docs|33 tests

Top Courses for Computer Science Engineering (CSE)

10 videos|99 docs|33 tests
Download as PDF
Explore Courses for Computer Science Engineering (CSE) exam

Top Courses for Computer Science Engineering (CSE)

Signup for Free!
Signup to see your scores go up within 7 days! Learn & Practice with 1000+ FREE Notes, Videos & Tests.
10M+ students study on EduRev
Related Searches

MCQs

,

Objective type Questions

,

ppt

,

Semester Notes

,

Viva Questions

,

Previous Year Questions: Thread | Operating System - Computer Science Engineering (CSE)

,

Previous Year Questions with Solutions

,

Exam

,

pdf

,

shortcuts and tricks

,

Summary

,

Previous Year Questions: Thread | Operating System - Computer Science Engineering (CSE)

,

Previous Year Questions: Thread | Operating System - Computer Science Engineering (CSE)

,

video lectures

,

mock tests for examination

,

Sample Paper

,

practice quizzes

,

Free

,

Important questions

,

past year papers

,

Extra Questions

,

study material

;