我在程序多线程程序中创建线程时,BoundsChecker给了我如下警告:
*********************************************************************
Description:A thread, which makes calls to one or more run-time library functions, was created using CreateThread. A thread that uses functions from the C run-time libraries should use the _beginthread and _endthread C run-time functions for thread management rather than CreateThread and ExitThread. Failure to do so results in small memory leaks when ExitThread is called.Note:
 If the run-time library is statically linked and the module lacks debug info, it may not be possible for the call to _beginthread to be detected and this error is reported. In this situation, the error can be safely suppressed.Sample Code:...
DWORD WINAPI aThread(void *arg)
{
    char *a = malloc (10);
    free (a);
    ExitThread(0);
}void main()
{
    int i;
    DWORD id;
    HANDLE hThread2[NUM_THREAD];    for (i = 0; i < NUM_THREAD; i++)
    {
        hThread2[i] = CreateThread(NULL, 0, aThread, NULL, 0, &id);
    }    WaitForMultipleObjects(NUM_THREAD, hThread2, TRUE, INFINITE);    for (i = 0; i < NUM_THREAD; i++)
    {
        CloseHandle(hThread2[i]);
    }
}
...RepairUse the C run-time functions _beginthread and _endthread to create and destroy threads, which use functions from the C run-time libraries.
*********************************************************************我用的是::AfxBeginThread()函数创建线程的,请问上面的Description是什么意思?

解决方案 »

  1.   

    A thread that uses functions from the C run-time libraries should use the _beginthread and _endthread C run-time functions for thread management rather than CreateThread and ExitThread. 调用C运行时函数的线程最好使用_beginthread来启动线程,他的作用是首先初始化C运行时的几个全局变量(C运行时的某些函数要用到这几个全局变量),然后调用CreateThread函数启动线程。如果你没有使用C运行时中的那几个函数,可以不理会这个警告,但最好是使用_beginthread来启动线程,这样比较安全。
      

  2.   

    如果你在控制台程序中用到了C Run-time library中的函数时最好用_beginthread函数来启动线程。这种警告是Microsoft VC编译器的早期警告,Microsoft曾经在相关文档中指出_beginthread这个函数有很多的bug,用他来启动线程并不合适,你可以用_beginthreadex函数来启动一个线程。关于CreateThread AfxBeginThread _beginthreadex这三个函数启动线程有什么区别请见
    http://expert.csdn.net/Expert/topic/2396/2396966.xml?temp=.9162104_beginthread和_beginthreadex函数的区别请见msdn中关于_beginthreadex函数的说明
    也可以参考《win32多线程程序设计》希望对你有所帮助!