Creating Multithreaded Applications

A program executes as a single, sequential flow of control. A program can also be designed to execute multiple tasks. To execute multiple tasks in your program, you can use threads. This chapter discusses implementation of threads and their life cycle. The chapter also discusses implementing multiple threads and prioritizing threads. In addition, this chapter discusses thread synchronization and communication between processes. | Creating Multithreaded Applications A program executes as a single sequential flow of control. A program can also be designed to execute multiple tasks. To execute multiple tasks in your program you can use threads. This chapter discusses implementation of threads and their life cycle. The chapter also discusses implementing multiple threads and prioritizing threads. In addition this chapter discusses thread synchronization and communication between processes. Objectives Chapter 11 In this chapter you will learn to fl Implement threads fl Define the life cycle of a thread fl Implement multiple threads fl Identify the thread priority fl Use synchronization in threads fl Identify communication between processes Implementing Threads A thread is defined as the execution path of a program. You can define a unique flow of a control in a program using a thread. Threads are used to run applications that perform large and complex computations. For example a Central Processing Unit CPU performs various complex tasks simultaneously. The processes include tasks such as writing and printing a document installing software and displaying the date and time on the status bar. All these processes are handled by separate threads. A process that is executed using one thread is known as a single-threaded process where the process is a running instance of a program. A single-threaded application can perform only one task at a time. You have to wait for one task to complete before another task can start. The following figure shows a single-threaded process. Thread A Single-Threaded Process To execute more than one task at a time you can create multiple threads in a program. A process that creates two or more threads is called a multithreaded process. For example any Web browser such as Internet Explorer is a multithreaded application. Within the browser you can print a page in the background while you scroll the page. Similarly you can play audio files and watch animated images at the .

Không thể tạo bản xem trước, hãy bấm tải xuống
TÀI LIỆU MỚI ĐĂNG
55    631    2    20-05-2024
Đã phát hiện trình chặn quảng cáo AdBlock
Trang web này phụ thuộc vào doanh thu từ số lần hiển thị quảng cáo để tồn tại. Vui lòng tắt trình chặn quảng cáo của bạn hoặc tạm dừng tính năng chặn quảng cáo cho trang web này.