Beginthread

The beginthread function creates a new thread of execution within the current process. It is part of the Microsoft Windows runtime library and is declared in the process.h header file.
Prototype
<syntaxhighlight lang="c">unsigned long _beginthread(void(* Func)(void*), unsigned Stack_size, void *Arg); </syntaxhighlight>
Func
Thread execution starts at the beginning of the function <code>func</code>. To terminate the thread correctly, <code>func</code> must call <code></code> or end with "return 0", freeing memory allocated by the run time library to support the thread.
Stack_size
The operating system allocates a stack for the thread containing the number of bytes specified by <code>stack_size</code>. If the value of <code>stack_size</code> is zero, the operating system creates a stack the same size as that of the main thread.
Arg
The operating system passes Arg to Func when execution begins. <code>Arg</code> can be any 32-bit value cast to void*.
Return value
Returns the operating system handle of the newly created thread. If unsuccessful, the function returns −1 and sets errno.
Compiler switches
To compile a program using multiple threads with the Microsoft C/C++ Compiler, you must specify the switch (or , for debug programs).

Comments