123ArticleOnline Logo
Welcome to 123ArticleOnline.com!
ALL >> Computer-Programming >> View Article

Threading And Multi-threading

Profile Picture
By Author: daniel
Total Articles: 19
Comment this article
Facebook ShareTwitter ShareGoogle+ ShareTwitter Share

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

Total Views: 173Word Count: 886See All articles From Author

Add Comment

Computer Programming Articles

1. Delhi’s Wordpress Wizards: Top Development Companies To Watch In 2024
Author: Unziplogic

2. Top Wordpress Seo Plugins To Boost Your Website’s Performance In 2024
Author: Rocket Press

3. Business Efficiency Through It Managed Services & Outsourcing
Author: Entrust Network Services

4. Explore The Top 7 Steps Of Developing Custom Gpt For Your Business
Author: Sonu Kumar

5. What Makes A Good Website? 5 Simple Tips For Small Businesses
Author: Yoggendar Shinde

6. How To Develop A Taxi Booking App? Types, Features, And Cost Estimations
Author: DC Kumawat

7. The Evolution Of App Development: Trends And Innovations Shaping The Future
Author: Backend Brains

8. How Much Cost Is Java Foundations Certification In Bhopal?
Author: Shankar Singh

9. Elevate Your E-commerce Game With Alvi Software’s Shopify Development Services
Author: Jeet Hanani

10. How App Development Companies Are Revolutionizing Industries In 2024
Author: Backend Brains

11. Latest & Ecommerce Technologies & Trends In 2024
Author: SpryBit Softlab

12. Elevate Your Tech Team: The Impact Of Hiring Top Node.js Programmers
Author: sanjay

13. Which Is The Best Institute For The Java Aadhaar Foundation Course In Bhopal?
Author: Shankar Singh

14. Boost Your Business Efficiency With Apptrop’s Industry-specific Tools
Author: apptrop

15. How Java Language Is Important In Programming?
Author: Java Learning Center

Login To Account
Login Email:
Password:
Forgot Password?
New User?
Sign Up Newsletter
Email Address: