I'm learning Multi Threading at the moment, in C#, but as with all learning I like to learn best practices. At the moment the area seems fuzzy. I understand the basics, and I can create threads.
What should I look out for when creating multi threaded applications. Are there any set rules or best practices that I should know about? Or anything to remember in order to avoid slip ups down the line?
Thanks for the responses.
Introduction to Multithreading Multithreading is the phenomenon of executing more than a thread in the system, where the execution of these threads can be of two different types, such as Concurrent and Parallel multithread executions.
A thread is a lightweight sub-process, the smallest unit of processing. Multiprocessing and multithreading, both are used to achieve multitasking. However, we use multithreading than multiprocessing because threads use a shared memory area.
Since a lot of kernel threads burden the system, there is restriction on the number of threads in the system. The many to one model maps many of the user threads to a single kernel thread. This model is quite efficient as the user space manages the thread management.
Applications which involve mechanism like validate and save, produce and consume, read and validate are done in multiple threads. Few examples of such applications are online banking, recharges, etc. It can be used to make games where different elements are running on different threads.
In addition to the MSDN Best Practices, I'll add:
Once you get more advanced, and are trying to optimize, other things to look for:
MSDN - Managed Threading Best Practices
That MSDN Article does a really good job at touching on the danger areas and giving the best practices for managing/working around those areas.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With