ALL >> Computer-Programming >> View Article
Threading And Multi-threading

Threading and Multi-threading Threading and multi-threading is often a more discussed aspect when it comes to application development. This is more applicable in the case of applications involving user interaction or high amount of processing which can be distributed evenly. For any application to be executed, the operating system normally creates a separate process for the application to be executed in its own space. This is a very normal confusion wherein there seems to be some ambiguity between a process and a thread. A process normally executes in its own memory space. A thread on the other hand can share the memory space used by the process under which it is executing. Meaning to say, a process by itself normally constitutes one or more threads under it. That just gets us to easily state that a thread is the very basic unit of an application processing to which the operating system allocates resources like processor time, memory, etc. to ensure that the goal of the application execution is achieved. The operating system creates an implementation of multitasking by supporting the effect of simultaneous execution of multiple ...
... threads from multiple processes. This is achieved by sharing the available processor time among the threads that need it and allocating the required resources to each thread one after another. The operating system basically achieves multitasking by putting a thread in a suspended state when it is time for the execution of the next thread in the queue. At the point of switching across from one thread to the other one, it basically saves all the data and the state associated with the particular thread in question and reloads it when it is time for the execution of the same back again. The length of the duration for which a particular thread is allowed to run depends on the availability of the resources, the processor speeds, etc. In reality, the time share is so small that as a user, we always feel that multiple threads are executing at the same time and hence multitasking is achieved. Any applications that we develop should always be implemented in such a way that they are capable of reacting to user actions as quickly as possible. The most recommended way of achieving this is by having our application use multithreads for processing and execution so that the application gives a better response to the user. Especially in applications that involve intense processing requirements it is always advisable and recommended to implement multi-threaded processing. That brings us to understand the concept of multi-threading and the pros and cons of implementing or using multi-threading within the application itself. Consider an example of an application where we can have the application do a file read/write operation and at the same time be able to print a document using separate threads that perform each of these actions. Improved performance provides improvement in the performance of the processor by simultaneous execution of computation and the I/O operation. Minimized system resource usage minimizes the use of system resources by using threads, which are the same address space and belong to the same process. Simultaneous access to multiple applications provides access to multiple applications at the same time because of quick context switching among threads. Program structure simplification simplifies the structure of complex applications, such as multimedia applications. As always, there is a downside to be implementing this kind of an approach in our application development. Since we already discussed that multiple threads within the same process share the same application that has been allocated to the process, there is always a chance for multiple threads to end up using the same memory location or variable or piece of data if proper care and safety has not been implemented. Other most common problems that come up with a multithreaded application implementation is a situation called a Dead-lock, where multiple threads try to gain access to the same resource which is either already locked or is currently non-accessible because of this situation of two threads trying to gain access to the same resource at the same time. Another normally observed problem is the situation when the program output becomes a bit unpredictable in a situation where the output changes depending on which thread has gained access to a particular resource or a data variable first. This is normally referred to in programming terms as a Race Condition. Multithreading is still frequently used in application design and implementation inspite of the problems that we saw listed above. The major usage of a multithreaded implementation is in a situation where we need the application to perform processing on one hand and also keep the user informed of the processing progress during this course. In traditional systems, if we have a processing that has been initiated on the database or any other IO Resource, it would be very difficult to also display the progress of the processing to the user. In this kind of situations, it is advisable to have the processing being allocated to a different application thread which is capable of raising notification events to the main thread that started off this thread. The main thread can then handle the responsibility of notifying the user and keeping the user informed of the status accordingly. This article is originally published at: threading and multi-threading
Add Comment
Computer Programming Articles
1. Career Opportunities After Completing The Best Business Analytics Courses In BhopalAuthor: Rohan Rajput
2. Network Security Essentials For It Professionals
Author: TCCI - Tririd Computer Coaching Institute
3. Emerging Programming Languages To Watch In 2026
Author: TCCI - Tririd Computer Coaching Institute
4. Python Scipy Tutorial: Simplifying Scientific And Technical Computing
Author: Tech Point
5. Is Scalatra The Right Fit For Your Web Framework Needs? Why You Should Hire Scalatra Developers Today
Author: Stellanova GlobalTech
6. Why Office 365 Is The Smartest Choice For Modern Businesses
Author: michellumb44
7. Why Choose Bhopal For The Best Business Analytics Courses? A Student’s Guide
Author: Rohan Rajput
8. Top Devops Certification Course In Chennai | Industry-ready Skills
Author: login360
9. Beyond The Code: Key Considerations When You Hire Software Developers For Skill And Cultural Alignment
Author: Stellanova GlobalTech
10. How Cism Certification Can Boost Your Cybersecurity Career
Author: Johnny
11. Which Is The Best Programming Language To Build A Mobile App?
Author: DianApps
12. Explore Career Growth With The Best Business Analytics Courses In Bhopal
Author: Rohan Rajput
13. From Zero To Hero: Python Pygame Tutorial For Aspiring Game Developers
Author: Tech Point
14. Beginner’s Python Pytorch Tutorial: Start Your Ai Journey Today
Author: Tech Point
15. Top 10 Cloud Security Threats And How To Prevent Them
Author: GIGABITTechnologies