2 * msvcrt.dll thread functions
4 * Copyright 2000 Jon Griffiths
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 #include "msvcrt/malloc.h"
23 #include "msvcrt/process.h"
25 #include "wine/debug.h"
27 WINE_DEFAULT_DEBUG_CHANNEL(msvcrt
);
29 /********************************************************************/
32 _beginthread_start_routine_t start_address
;
34 } _beginthread_trampoline_t
;
36 /*********************************************************************
37 * _beginthread_trampoline
39 static DWORD CALLBACK
_beginthread_trampoline(LPVOID arg
)
41 _beginthread_trampoline_t local_trampoline
;
43 /* Maybe it's just being paranoid, but freeing arg right
46 memcpy(&local_trampoline
,arg
,sizeof(local_trampoline
));
49 local_trampoline
.start_address(local_trampoline
.arglist
);
53 /*********************************************************************
54 * _beginthread (MSVCRT.@)
56 unsigned long _beginthread(
57 _beginthread_start_routine_t start_address
, /* [in] Start address of routine that begins execution of new thread */
58 unsigned int stack_size
, /* [in] Stack size for new thread or 0 */
59 void *arglist
) /* [in] Argument list to be passed to new thread or NULL */
61 _beginthread_trampoline_t
* trampoline
;
63 TRACE("(%p, %d, %p)\n", start_address
, stack_size
, arglist
);
65 /* Allocate the trampoline here so that it is still valid when the thread
66 * starts... typically after this function has returned.
67 * _beginthread_trampoline is responsible for freeing the trampoline
69 trampoline
=MSVCRT_malloc(sizeof(*trampoline
));
70 trampoline
->start_address
= start_address
;
71 trampoline
->arglist
= arglist
;
74 return CreateThread(NULL
, stack_size
, _beginthread_trampoline
, trampoline
, 0, NULL
);
77 /*********************************************************************
78 * _beginthreadex (MSVCRT.@)
80 unsigned long _beginthreadex(
81 void *security
, /* [in] Security descriptor for new thread; must be NULL for Windows 9x applications */
82 unsigned int stack_size
, /* [in] Stack size for new thread or 0 */
83 _beginthreadex_start_routine_t start_address
, /* [in] Start address of routine that begins execution of new thread */
84 void *arglist
, /* [in] Argument list to be passed to new thread or NULL */
85 unsigned int initflag
, /* [in] Initial state of new thread (0 for running or CREATE_SUSPEND for suspended) */
86 unsigned int *thrdaddr
) /* [out] Points to a 32-bit variable that receives the thread identifier */
88 TRACE("(%p, %d, %p, %p, %d, %p)\n", security
, stack_size
, start_address
, arglist
, initflag
, thrdaddr
);
91 return CreateThread(security
, stack_size
, (LPTHREAD_START_ROUTINE
) start_address
,
92 arglist
, initflag
, (LPDWORD
) thrdaddr
);
95 /*********************************************************************
96 * _endthread (MSVCRT.@)
106 /*********************************************************************
107 * _endthreadex (MSVCRT.@)
110 unsigned int retval
) /* [in] Thread exit code */
112 TRACE("(%d)\n", retval
);