A random talk on C + + Builder Multithread Programming technology

Source: Internet
Author: User
Tags thread

Absrtact: This article briefly introduces the meaning of multithreaded programming in Windows environment, discusses the problem of developing multi-threaded application in C++builder environment, and helps us to understand the synchronization concept and its realization method better by realizing the producer-consumer problem.

Keywords: multithreading; synchronization; producer-consumer; c++builder

The feasibility of thread threads

In many cases, you might want to create a thread for your program. Here are some of the possibilities:

(1) If you are creating a multiple document interface (multiple document INTERFACE,MDI) program, it is important to assign a thread to each window, for example, for an MDI communication program that connects to multiple hosts simultaneously through multiple modems, If each window has its own thread to communicate with a host, the whole thing is much simpler.

(2) If you are using a machine with multiple processors and want to take full advantage of all possible CPU resources, you need to break the application into multiple threads. The CPU in the Windows2000 is divided into threads. Therefore, if the program contains only one thread, the program can only use one of the CPUs in the default environment. However, if you divide this program into multiple threads, Windows2000 can run individual threads on different CPUs.

(3) Some tasks running in the background require the user to continue working with the application. This is easy to implement with threads. For example, you can put some tedious, page formatting, reading and writing of files in a separate thread so that it runs in the background without affecting the user.

Synchronous

One of the most challenging questions about composing multithreaded routines is how to get one thread to work with another thread. This raises a very important question: synchronization. Synchronization refers to the ability of processes, threads to communicate with each other to avoid damaging their data. The synchronization problem in Windows environment is caused by the CPU time slice allocation of the WIN32 system. Although at some point only one thread occupies the CPU (single CPU) time, it is not known when and where the thread is interrupted, so it is important to ensure that the threads do not break each other's data. The problem of synchronization is so important and interesting that it attracts a lot of scholars to study it, thus producing a series of classic process synchronization problems, which are more representative of "producer-consumer Problem", "reader-writer problem", "philosopher dining problem" and so on. In this paper, we briefly discuss how to realize the "producer-consumer" problem under the C++builder platform, and help us to better understand the concept of synchronization and its realization method.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.