using namespace std;
void __declspec(dllexport) CalculateFunc(
int
count)
{
int
index
=
0
;
for
(
int
i
=
0
; i < count; i
+
+
)
{
printf(
"i=%d, %d...\n"
, i,
+
+
index);
Sleep(
1000
);
}
printf(
"Threader Over...\n"
);
}
int
g_indexRef
=
0
;
void myThread(
int
count)
{
__asm
{
push eax
mov eax, esp
sub eax,
0x10
mov g_indexRef, eax
push count
call CalculateFunc
add esp,
4
pop eax
}
}
void CalculateFuncAsync()
{
std::thread thread(myThread,
100
);
thread.join();
/
/
等待线程结束
}
int
main()
{
std::thread thread(CalculateFuncAsync);
Sleep(
3000
);
if
(g_indexRef)
{
*
((
int
*
)g_indexRef)
=
100
;
thread.join();
}
printf(
"Main Over...\n"
);
return
0
;
}