Multithreading caveats

Although there are many benefits to multithreading, there are some caveats that need to be thoroughly addressed when writing multithreaded applications. If the machine is a single or two-core machine and the application is creating lots of threads, the context switching between these threads will slow the performance:

The preceding diagram depicts the program running on a single-processor machine. The first task executes synchronously, and runs comparatively faster than the three threads running on the single processor. The system executes the first thread, then waits for a while before moving on to execute the second thread, and so on. This adds an unnecessary overhead of switching between threads and, thus, delays the overall operation. In the field of threading, this is known as context switching. The boxes between each thread represent the delay occurring during each context switch between threads.

As far as the developer experience is concerned, debugging and testing are two other issues that are challenging for developers when creating a multithreaded application.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.137.213.235