Users Online

· Guests Online: 89

· Members Online: 0

· Total Members: 188
· Newest Member: meenachowdary055

Forum Threads

Newest Threads
No Threads created
Hottest Threads
No Threads created

Latest Articles

C# Questions & Answers ? Multithreaded Programming ? 2

C# Questions & Answers – Multithreaded Programming – 2

 

 

This set of C# Interview Questions and Answers for freshers focuses on “Multithreaded Programming II”.

 

 

 

1. Which of these keywords are used to implement synchronization?
a) synchronize
b) syn
c) synch
d) synchronized

Answer: d
Explanation: None.

 

 

 

2. Which keyword is used for using the synchronization features defined by the Monitor class?
a) lock
b) synchronized
c) monitor
d) locked

Answer: a
Explanation: The C# keyword lock is really just shorthand for using the synchronization features defined by the Monitor class, which is defined in the System.Threading namespace.

 

 

 

3. What is synchronization in reference to a thread?
a) It’s a process of handling situations when two or more threads need access to a shared resource
b) It’s a process by which many threads are able to access the same shared resource simultaneously
c) It’s a process by which a method is able to access many different threads simultaneously
d) It’s a method that allows too many threads to access any information they require

Answer: a
Explanation: When two or more threads need to access the same shared resource, they need some way to ensure that the resource will be used by only one thread at a time, the process by which this is achieved is called synchronization.
 

 

 

4. Which method is called when a thread is blocked from running temporarily?
a) Pulse()
b) PulseAll()
c) Wait()
d) Both Pulse() & Wait()

Answer: c
Explanation: When a thread is temporarily blocked from running, it calls Wait( ). This causes the thread to go to sleep and the lock for that object to be released, allowing another thread to acquire the lock.

 

 

 

5. What kind of exception is being thrown if Wait(), Pulse() or PulseAll() is called from code that is not within synchronized code?
a) System I/O Exception
b) DivideByZero Exception
c) SynchronizationLockException
d) All of the mentioned

Answer: c
Explanation: A SynchronizationLockException will be thrown if Wait(), Pulse(), or PulseAll() is called from code that is not within synchronized code, such as a lock block.
 

 

 

 

6. What is mutex?
a) a mutually exclusive synchronization object
b) can be acquired by more than one thread at a time
c) helps in sharing of resource which can be used by one thread
d) all of the mentioned

Answer: a
Explanation: A mutex is a mutually exclusive synchronization object. This means it can be acquired by one and only one thread at a time. The mutex is designed for those situations in which a shared resource can be used by only one thread at a time.

 

 

 

7. What is Semaphore?
a) Grant more than one thread access to a shared resource at the same time
b) Useful when a collection of resources is being synchronized
c) Make use of a counter to control access to a shared resource
d) All of the mentioned

Answer: d
Explanation: A semaphore is similar to a mutex except that it can grant more than one thread access to a shared resource at the same time. Thus, the semaphore is useful when a collection of resources is being synchronized. A semaphore controls access to a shared resource through the use of a counter. If the counter is greater than zero, then access is allowed. If it is zero, access is denied.

 

 

 

 

8. Which method is used to abort thread prior to it’s normal execution?
a) sleep()
b) terminate()
c) suspend()
d) Abort()

Answer: d
Explanation: To terminate a thread prior to its normal conclusion, use Thread.Abort( ). Its simplest form is shown here:

 

 public void Abort()

Abort() causes a ThreadAbortException to be thrown to the thread on which Abort() is called. This exception causes the thread to terminate.

 

 

 

9. Which of these statements is incorrect?
a) By multithreading CPU idle time is minimized, and we can take maximum use of it
b) By multitasking CPU idle time is minimized, and we can take maximum use of it
c) Two thread in Csharp can have same priority
d) A thread can exist only in two states, running and blocked

Answer: d
Explanation: Thread exists in several states, a thread can be running, suspended, blocked, terminated & ready to run.

 

 

 

 

10. What is multithreaded programming?
a) It’s a process in which two different processes run simultaneously
b) It’s a process in which two or more parts of same process run simultaneously
c) It’s a process in which many different process are able to access same information
d) It’s a process in which a single process can access information from many sources

Answer: b
Explanation: Multithreaded programming a process in which two or more parts of same process run simultaneously.

 

Comments

No Comments have been Posted.

Post Comment

Please Login to Post a Comment.

Ratings

Rating is available to Members only.

Please login or register to vote.

No Ratings have been Posted.
Render time: 1.21 seconds
10,830,519 unique visits