What is thread? How to create a thread in a win32 application?

What is a stream? How to create a thread in a win32 application?

+3
source share
5 answers

Thread is an easy process. A thread can be freely defined as a separate thread of execution that occurs simultaneously and independently of everything else that can happen. A thread is like a classic program that starts at point A and runs until it reaches point B. There is no event loop in it. A thread works regardless of everything that happens on the computer. Without threads, an entire program can be supported by one intense CPU task or one infinite loop, intentionally or otherwise. In threads, other tasks that do not get stuck in the loop can continue processing without waiting for the stuck task to complete. Please follow this link for more information and its comparison with the process.

http://en.wikipedia.org/wiki/Thread_(computer_science)

, ....

, i.e ThreadFun1

#include<windows.h>
#include<stdio.h>
#include<conio.h>

void __stdcall ThreadFun1()
{
    printf("Hi This is my first thread.\n");
}
void main()
{
    printf("Entered In Main\n");
    HANDLE hThread;
    DWORD threadID;
    hThread = CreateThread(NULL, // security attributes ( default if NULL )
                            0, // stack SIZE default if 0
                            ThreadFun1, // Start Address
                            NULL, // input data
                            0, // creational flag ( start if  0 )
                            &threadID); // thread ID
    printf("Other business in Main\n"); 
    printf("Main is exiting\n");
    CloseHandle(hThread);
    getch();
}
+8

CreateThread(), _beginthreadex() , C/++.

_beginthreadex() C/++, CreateThread() .

+3

- , , Windows CE.

, CreateThread. .

Windows CE 6.

+1

CreateThread()

.

Streams, as a rule, should be created using _beginthread()or _beginthreadex(), in order to ensure the correct initialization of the thread-local structures of the C / C ++ runtime environment.

See a discussion of this question for more details: Windows threading: _beginthread vs _beginthreadex vs CreateThread C ++

0
source

Source: https://habr.com/ru/post/1726533/


All Articles