Windows core Programming Reading notes-sixth chapter Threading Basics

Source: Internet
Author: User

1. Compared to threads, processes use more system resources. The reason for this is the address space. Creating a virtual address space for a process requires a lot of system resources. Threads have only one kernel object and one stack.

2. Entry functions for threads

DWORD WINAPI ThreadFunc (PVOID pvparam) {DWORD dwresult = 0;...return (dwresult);}

Several descriptions of thread functions

    • Thread functions can be arbitrarily named.
    • A thread function has only one parameter, and its meaning is defined by us (not the operating system). Therefore, we do not have to worry about ansi/unicode problems.
    • A thread function must return a value that becomes the exit code for that thread.
    • Thread functions should use function arguments and local variables whenever possible. The parameters and local variables of the function are created on the thread stack.

3.CreateThread function

HANDLE CreateThread (psecurity_attributes psa,dword cbstacksize,pthread_start_routine pfnstartaddr,pvoid PvParam, DWORD Dwcreateflags,pdword Pdwthreadid);

Calling the CreateThread function, the system allocates memory from the process's address space to the thread stack for use. The new thread runs in the same process context as the thread responsible for creating it. Therefore, the new thread can access all the handles of the process kernel object, all the memory in the process, and the stack of all the other threads in the same process .

Windows core Programming Reading notes-sixth chapter Threading Basics

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.