Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

How to write a multithread class for C++?

Status
Not open for further replies.

tooti

Newbie level 3
Newbie level 3
Joined
Oct 2, 2005
Messages
3
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,306
Hi all,
I would like to now how to write a multithread class for C++.
If possible please give me some examples.
Thx
 

Re: about multithread

In C++ Builder you can do it:


#include <vcl.h>
#pragma hdrstop


TMyThread *MyThread;

__fastcall TMyThread::TMyThread(bool CreateSuspended)
: TThread(CreateSuspended)
{
//tpIdle The thread executes only when the system is idle. Windows won't
//interrupt other threads to execute a thread with tpIdle priority.
//tpLowest The thread's priority is two points below normal.
//tpLower The thread's priority is one point below normal.
//tpNormal The thread has normal priority.
//tpHigher The thread's priority is one point above normal.
//tpHighest The thread's priority is two points above normal.
//tpTimeCritical The thread gets highest priority.
Priority = tpHighest;
}

void __fastcall TMyThread::Execute()
{
// Thread code here!!!!
}

For create others just give another name and repeat the procedure


leomecma
 

Re: about multithread

If you want to "bypass" compiler/IDE specific overload, you can build your class on top of CreateThread win32API. But, beware of threading bug, use mutexes and other "safeguards". I've been bitten by threading bug a few months ago (in MSVC++6), and its debugger can not find the bug. Only after watching the Windows Task Manager I can see that something went wrong with the CPU usage, from there I know that, it must be a threading bug. After fixing the corresponding module synchronization routine, everything went good. Just a caution though ;)
 

about multithread

Hi,
refer msdn for writing multithreaded application, you would probably have array of object of class CWinThread if you are using MFC or you need to manage thread handles in an array, i assume you want to encapsulate creation of threads and manage it.
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top