32位沒問題,切換到64位,用了各種辦法創建執行緒都是很慢,100個執行緒都需要一分鐘左右。
(1)CreateThread(NULL,0,(LPTHREAD_START_ROUTINE)funs,NULL,0, NULL);
(2)_beginthread(funsss, 0, NULL );
(3)(HANDLE *)_beginthreadex(NULL,0,fun,(void *)this,CREATE_SUSPENDED,NULL);
ResumeThread(threadHandle);
(4)thread t(funss);
t.detach();
(5)TMyThread *secondProcess;
secondProcess = new TMyThread(True); // Creation is suspended--second process does not run yet.
secondProcess->FreeOnTerminate = True; // Do not need to clean up after termination.
secondProcess->Priority = tpLower; // Set the priority to lower than normal.
secondProcess->Resume(); // Now run the thread.
以上五種創建執行緒的方法都嘗試了,32位速度很快,3秒就可以創建完畢,但是64位至少需要一分鐘。哪位大神能解答下為什么 ?
用的編譯器是rad studio 10.2
uj5u.com熱心網友回復:
使用Release模式試一下,在DEBUG模式下,創建執行緒是有卡頓uj5u.com熱心網友回復:
release 版本也不行。。。uj5u.com熱心網友回復:
有人知道啥原因么?uj5u.com熱心網友回復:
關掉IDE,單獨運行exe檔案,看看時間,如果還不行,把這段代碼放到VC里面跑一下,如果VC沒問題,那就是CB的原因了。。不過CB出什么問題都不要感到奇怪。。uj5u.com熱心網友回復:
CB 10.2.1(bcc64 7.30)實測沒有樓主說的問題:
#include <stdio.h>
#include <stdint.h> // used by C++Builder only
#include <process.h>
#include <windows.h>
struct AAA
{
int i = 0;
uintptr_t _handle;
// void Init() {_handle = _beginthread(Thread, 0, this);}
void Init() {_handle = _beginthreadex(NULL, 0, Thread, this, CREATE_SUSPENDED, NULL);}
static unsigned int __stdcall Thread(void *Args);
};
unsigned int __stdcall AAA::Thread(void *Args)
{
AAA *This = (AAA *)Args;
while (1)
{
printf("thread #%p -> %d\n", (void *)This->_handle, This->i++);
Sleep(100);
}
return 0;
}
int main()
{
AAA a, b;
a.Init();
b.Init();
ResumeThread((HANDLE)a._handle);
Sleep(100);
ResumeThread((HANDLE)b._handle);
getchar();
return 0;
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/37679.html
上一篇:包裹繼承問題
下一篇:數字邏輯設計
