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
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
 

leomecma

Full Member level 5
Joined
Jun 17, 2005
Messages
242
Helped
14
Reputation
28
Reaction score
1
Trophy points
1,298
Location
Brasil
Activity points
3,917
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
 

Pinczakko

Full Member level 2
Joined
Jul 29, 2004
Messages
138
Helped
13
Reputation
26
Reaction score
0
Trophy points
1,296
Location
Taka Bonerate National Park, Indonesia
Activity points
1,592
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 ;)
 

sshahid47

Advanced Member level 4
Joined
Nov 5, 2004
Messages
101
Helped
15
Reputation
30
Reaction score
2
Trophy points
1,298
Activity points
974
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

Top