What should you do?

You work as the application developer at Domain.com. Domain.com uses Visual Studio.NET 2005 as its application development platform.
You are developing a .NET Framework 2.0 Windows Service application that will be used on a multiprocessor system.
You are writing code for a class that contains globally accessible Integer variable named Testcounter.
The value of the Testcounter will be incremented of decremented from other classes running in separate threads.
You are required to provide atomic and non-blocking updates for the Testcounter whilst your solution provides the best performance.
What should you do?

You work as the application developer at Domain.com. Domain.com uses Visual Studio.NET 2005 as its application development platform.
You are developing a .NET Framework 2.0 Windows Service application that will be used on a multiprocessor system.
You are writing code for a class that contains globally accessible Integer variable named Testcounter.
The value of the Testcounter will be incremented of decremented from other classes running in separate threads.
You are required to provide atomic and non-blocking updates for the Testcounter whilst your solution provides the best performance.
What should you do?

A.
The Interlocked class should be used

B.
The Overlapped class should be used

C.
The SynchronizationContext class should be used

D.
The SyncLock statement should be used

Explanation:
For this particular scenario the Interlocked class is ideal because you are required to provide atomic and non-blocking updates for a data item.
Incorrect Answers:
B: This option should not be used in the scenario because it is used to transfer information to Win32 API functions.
C: This operation should not be used as you will not be providing atomic and non-blocking updates.
D: This option should not be used as it does not offer atomic operations and offers inferior performance compared to the Interlocked class.



Leave a Reply 1

Your email address will not be published. Required fields are marked *