🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.cppbuilder.nativeapi
Article #14796

Threads and CPU Usage

#14796
From: Joe Walker
Date: Sun, 03 Aug 2003 12:19
37 lines
1728 bytes
Hi all,
I have a thread which has 2 other threads..
I send message from the main thread to member threads by
PostThreadMessage(ThreadID,msg,...)
like
class ThreadA: : public TThread
{
public:
        TThreadB SecondThread;
        TThreadC ThirdThread;
}


What is the best way to handle this messages in other threads. (in order to
have CPU usage below %100)
I have seen many codes like,

while (!Terminated)
   if (PeekMessage(&msg, NULL, 0,0,PM_REMOVE))
                        Dispatch(&msg);
else
    WaitMessage();

OR

 while (GetMessage(&msg, NULL, 0,0,PM_REMOVE))
    Dispatch(&msg)

OR any other things...

Whatever I do (I think) , CPU usage seems to be %100..

I have also tried Sleep and it doesnt work..
So what is the best way?
Note: I have not any windows in my threads...:)

JoeW
Technical Details
Message-ID: <3f2cfdce$1@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-06!sn-xit-01!sn-xit-09!supernews.com!news.maxwell.syr.edu!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 10cc67,90beddda6c283d0e,start
X-Google-Attributes: gid10cc67,public
X-Google-ArrivalTime: 2003-08-03 05:39:22 PST
From: "Joe Walker" <__JoeW@hotmail.com>
Newsgroups: borland.public.cppbuilder.nativeapi
Subject: Threads and CPU Usage
Date: Sun, 3 Aug 2003 15:19:30 +0300
Lines: 43
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2800.1106
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1106
NNTP-Posting-Host: 144.122.180.3
Message-ID: <3f2cfdce$1@newsgroups.borland.com>
X-Trace: newsgroups.borland.com 1059913166 144.122.180.3 (3 Aug 2003 05:19:26 -0700)
Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-06!sn-xit-01!sn-xit-09!supernews.com!news.maxwell.syr.edu!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail