Windows core programming (Summary)

Source: Internet
Author: User
1. c r e a t e t h r e a D function is used to create the WI n o w s function of the thread. However, if you are writing C/C ++ code, you should never call C r e a t e t h r e a D. Instead, use the Runtime library function _ B e g I n t h r e a d e x. the reason is simple. The operating system does not know how to manage the stack space in each language, calling the _ B e g I n t h r e a d e x function of CPP will call the createthread function to create a thread,

2. The first thing to consider is, "Why must one library be used for a Single-threaded application and another library for a multi-threaded application ?". The reason is that the inventor of the Runtime Library did not consider using the C Runtime Library for Multithreaded Applications

3. the purpose of creating these two functions is to execute the functions of _ B e g I n t h r e a d e x and _ e n d t h r e a d e x. However, as you can see, the _ B e g I n t h r e a D function has fewer parameters, therefore, the fully-bitwise _ B e g I n t h r e a d e x function is subject to greater restrictions.
3. resumethread run and suspend Processes
Suspendthread

4. suspendprocess pause all threads in the process

5. 0 can be passed to s l e p. This tells the system that the calling thread will release the remaining time slices and force the system to schedule another thread. However, the system can reschedule the thread that just called s l e p.

6. Wi n d o w s provides a function called g e t h r e a d Ti m e s to obtain the thread running time.

7. atomic operation: interlockedexchangeadd

8. wi n d o w s does provide other methods for data communication between processes, but these methods are implemented using memory ing files, this makes the memory ing file the most effective way for multiple processes on a single computer to communicate with each other. Note that memory ing should be the most effective method for inter-process communication on a single machine. The following is the main method for memory ing:

To use a memory ing file, follow these steps:

1) Create or open a file kernel object to identify the file on the disk that you want to use as the memory ing file.

2) create a file ing kernel object to tell the system the file size and how you plan to access the file.

3) Let the system map all or part of the file ing object to your process address space.

When using the memory ing file, you must perform the following steps to clear it:

1) Tell the system to cancel the image mapped to the kernel object from the address space of your process.

2) disable the file ing kernel object.

3) disable file kernel objects

Note that if you call the C r e a t e I l e m a p I n g function, pass the pa g e _ r e a d w r I t e sign, then the system will try to ensure that the size of the data files on the disk is at least d w m a x I m u m s I z e h I g h and
The size specified in the d w m a x I m u m s I Z E L O W parameter is the same. If the file size is smaller than the set size, the C r e a t e I l e m a p I n g function will expand the file size and increase the file size on the disk. This expansion is necessary. In this way, when the file is used as a memory ing file in the future, the physical memory will already exist. This can improve the efficiency of large file operations.

If all processes that communicate with each other are on the same computer, all the mechanisms mentioned above use memory ing files for their tedious work. If high performance and low overhead are required, the memory ing file is the best mechanism available for raising hands. The method is as follows:
Static handle s_hfilemap = NULL;
S_hfilemap = createfilemapping (invalid_handle_value, null,
Page_readwrite, 0, 4*1024, text ("mmfshareddata"); here, mmfshareddata identifies the shared data between processes.

9.

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.