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. Custom Web Development Solutions In Surat For Growing BusinessesAuthor: sassy infotech
2. Video Streaming App Development: 12 Key Features, Architecture And Cost
Author: Byteahead
3. Understanding Google Analytics Events
Author: Byteahead
4. Types Of Learning Management Systems
Author: Byteahead
5. How To Choose The Best Coding Institute In Bhopal?
Author: Shankar Singh
6. Top Tech Trends Real Estate Companies Should Focus
Author: Byteahead
7. Top Erp Trends And The Future Of Enterprise Resource Planning
Author: Byteahead
8. Top Elearning Solutions
Author: Byteahead
9. Top 7 App Prototyping Tools For A Great Ux Design
Author: Byteahead
10. Revolutions.ai
Author: Redefining the Future with Smart Solutions
11. Comment Contacter Facebook : Guide Complet Pour Obtenir De L'aide Rapide
Author: blackadam
12. Deepfake Or Faceswap? Understanding The Differences
Author: Louis Cartier
13. What Is The Best Institute To Learn Java Programming In Bhopal?
Author: Shankar Singh
14. Amazon Product Listing Services: Elevating Your E-commerce Game
Author: rachelvandereg
15. Overcoming Challenges With Smart Invoice Pos Software For Retail Stores In Zambia
Author: Cecilia Robert