vinay_13
asked on
Mulithreading in c++
How do you implement multithreading in c++? What are the basic steps?
Multithreading is platform-dependent, so you can't give any one answer without knowing the operating system and compiler. However, there are some nice thread-supporting classes in the boost libraries (at www.boost.org) that you can use to make threading the same across platforms.
It all depends. If you're using MFC you can use AFXBeginThread which is a simple thread class. It's not too robust but it's adequate for most simple tasks.
Here's a link to that:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vcmfc98/html/_mfc_afxbeginthread.asp
There's also CWinThread or the Win32 Call CreateThread. Here's an overall good link with examples for the bunch.
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnw98bk/html/makingmodifyingthreads.asp
You might also want to user CCriticalSection in places if your multiple threads might access the same data or resources. A good example where threads can make a mess of things is when they write data to files. There are better ThreadLocking classes you might consider instead, like CSingleLock or CMutex.
Here's a link to that:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vcmfc98/html/_mfc_afxbeginthread.asp
There's also CWinThread or the Win32 Call CreateThread. Here's an overall good link with examples for the bunch.
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnw98bk/html/makingmodifyingthreads.asp
You might also want to user CCriticalSection in places if your multiple threads might access the same data or resources. A good example where threads can make a mess of things is when they write data to files. There are better ThreadLocking classes you might consider instead, like CSingleLock or CMutex.
The first step to properly using multiple threads is to get pretty deep into some reading. Threads are probably the most powerful tools that you can be given to shoot yourself in the foot. Jumping into them without understanding the thread lifecycle, contention, synchronization and the like will probably be very painful. I'm all for using them, but be sure you play with them using small examples and work your way up.
brian
brian
ASKER
Dear mnashadka, I'm working in DOS with Turbo c++ compiler.
i also have windows but i need this to work in case only dos is available
i also have windows but i need this to work in case only dos is available
DOS is a single-tasking O/S. The short answer is "It can't be done"
-- Dan
-- Dan
Yes it can be done, I did it before with Borland C++ 3.1.
But you need to write, or search, a special routines to do that.
But you need to write, or search, a special routines to do that.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.