Click to See Complete Forum and Search --> : _beginthread and _endthread
xander_tan
March 3rd, 2004, 09:46 PM
What are _beginthread and _endthread?
I saw some network programming use that functions in sending and receive message.
I read on some websites, they written that _beginthread and _endthread are used for multithreading. This problem makes me more confuse, I can't imagine the flowchart of the program anymore.
Could anyone explain it to me?
Thanks,
Mathew Joy
March 4th, 2004, 02:36 AM
As the name suggets it is used to begin and end a thread. I suggest you take a book and learn about multithreading. Then the program may look more clear to you.
Andreas Masur
March 4th, 2004, 05:10 AM
[Moved thread]
Andreas Masur
March 4th, 2004, 05:14 AM
Well...as being mentioned, they are used for creating and ending threads. However, discussing the whole concept of multithreading cannot be done within one post. So, I would rather suggest getting a tutorial to get the basic understanding...such as this article (http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dllproc/base/processes_and_threads.asp)...
xander_tan
March 4th, 2004, 10:23 AM
Thanks, I'll read first... coz I really donnoe anything, just read sample source and get confuse ^^
Sam Hobbs
March 4th, 2004, 12:23 PM
Also see my Sample _beginthreadex (http://simplesamples.info/Windows/_beginthreadex.php). That page was in my web site previously but somehow got lost when I restored my web site recently. I restored the page to my web site just now.
xander_tan
March 5th, 2004, 06:34 AM
Thanks for you all! I got it now...
I've tried it in Visual C++ 6.0.
But why can't I use _beginthread or _endthread in Visual C++ .NET?
j0nas
March 5th, 2004, 10:27 AM
You should be able to use _beginthread(ex) functions in VC++.NET... However, if you're programming managed C++, you should use the .NET classes for threading.
Andreas Masur
March 6th, 2004, 04:21 PM
Originally posted by xander_tan
But why can't I use _beginthread or _endthread in Visual C++ .NET?
Well...why can't you? In other words...what is the error?
xander_tan
March 10th, 2004, 06:47 AM
Now I can use it in VC++ .NET ^^
One of my friend told me to change the run time to Multi-threaded
And I got a lot of errors:
Linking...
libcpmtd.lib(xdebug.obj) : error LNK2019: unresolved external symbol __malloc_dbg referenced in function "void * __cdecl operator new(unsigned int,struct std::_DebugHeapTag_t const &,char *,int)" (??2@YAPAXIABU_DebugHeapTag_t@std@@PADH@Z)
libcpmtd.lib(locale.obj) : error LNK2001: unresolved external symbol __malloc_dbg
libcpmtd.lib(_tolower.obj) : error LNK2019: unresolved external symbol __malloc_dbg referenced in function __Tolower
libcpmtd.lib(xwcsxfrm.obj) : error LNK2019: unresolved external symbol __malloc_dbg referenced in function __Wcsxfrm
libcpmtd.lib(xdebug.obj) : error LNK2019: unresolved external symbol __free_dbg referenced in function "void __cdecl operator delete(void *,struct std::_DebugHeapTag_t const &,char *,int)" (??3@YAXPAXABU_DebugHeapTag_t@std@@PADH@Z)
libcpmtd.lib(xwcsxfrm.obj) : error LNK2001: unresolved external symbol __free_dbg
libcpmtd.lib(locale.obj) : error LNK2019: unresolved external symbol __realloc_dbg referenced in function "private: void __thiscall std::locale::_Locimp::_Addfac(class std::locale::facet *,unsigned int)" (?_Addfac@_Locimp@locale@std@@AAEXPAVfacet@23@I@Z)
libcpmtd.lib(xmbtowc.obj) : error LNK2019: unresolved external symbol __CrtDbgReport referenced in function __Mbrtowc_lk
Debug/thread.exe : fatal error LNK1120: 4 unresolved externals
Then in a few days I didn't touch it. Today, I tried to change /MT to another option, I use /MTd. And it's working. I changed the option because I read the default run time is Single-threaded debug.
So, why it can work in /MTd but cannot work in /MT?
Andreas Masur
March 10th, 2004, 07:12 AM
Originally posted by xander_tan
So, why it can work in /MTd but cannot work in /MT?
Because the former one is the debug library and the latter one the release one...
Mick
March 10th, 2004, 07:13 AM
even if you change it to /MT you should not get link errors...maybe hardcoded some .lib somehwere?
a listing of your project settings or your project in a .zip file would help...
IsaacTheIceMan
October 15th, 2004, 06:53 AM
use /MD
MSDN:
/MD Defines _MT and _DLL so that both multithread- and DLL-specific versions of the run-time routines are selected from the standard .h files. This option also causes the compiler to place the library name MSVCRT.lib into the .obj file.
Applications compiled with this option are statically linked to MSVCRT.lib. This library provides a layer of code that allows the linker to resolve external references. The actual working code is contained in MSVCR71.DLL, which must be available at run time to applications linked with MSVCRT.lib.
When /MD is used with _STATIC_CPPLIB defined (/D_STATIC_CPPLIB) it will cause the application to link with the static multithread Standard C++ Library (libcpmt.lib) instead of the dynamic version (msvcprt.lib) while still dynamically linking to the main CRT via msvcrt.lib.
It seems you must use /MD when using the std namespace in VS .NET. Otherwise, you will reciece errors saying that the linker has an unresolved external symbol for both new and delete. Adding /D_STATIC_CPPLIB to the command line along with /MD brings back the errors.
codeguru.com
Copyright 2007 Jupitermedia Corporation All Rights Reserved.