Article View: borland.public.cppbuilder.internet.socket
Article #1301Re: Passing info between threads
From: Paul at NCF
Date: Tue, 20 Feb 2007 08:09
Date: Tue, 20 Feb 2007 08:09
56 lines
2545 bytes
2545 bytes
Hi,
Off to work soon, so just in case this helps, an example help thread:
void
ClientTask::SendAMessage( int ID,
char * Message )
{
if (MyMbx)
{
// class/structure to add params to input Q
AMessage * sl = new AMessage( int ID, char * Message );
// My own thread safe mainbox, add item to end of list. It has
critical section around add and remove methods,
// and signals the thread using its TEvent when adding
// You could use TThreadList (LockList, UnlockList, Add, Remove
etc), and TEvent directly: event->SetEvent();
MyMbx->AddMailMsg(sl);
}
}
ClientTask::Execute()
{
while (!Terminated))
{
// get msg off queue, if one exists (thread safe), or TThreadList
msg = (AMessage *) MyMbx->RemoveMailMsg();
// if no msg, wait for wakeup
if (!msg)
{
// wait for multiple objects API using TEvent handle, or
timeout
signalled = WaitForWakeUp(1000);
// get message off fron of Q, as before this is my Q system, but
you could use TThreadList
msg = (AMessage *) MyMbx->RemoveMailMsg();
}
// if msg on queue, send
if (msg)
{
SendToServer(msg);
delete msg;
}
} // do forever (or nearly)
}
> That's the effect I'm trying to achieve, but I'm having trouble figuring
> out a thread-safe method of doing that.
Technical Details
Message-ID:
<45daac91@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!g2news2.google.com!news1.google.com!news3.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mailReferences:
<45d9e83a$1@newsgroups.borland.com> <45da1385@newsgroups.borland.com> <45da1b21$1@newsgroups.borland.com>Show Full Headers
Complete Article Headers
X-Google-Thread: 11508e,234a9a04e64155b0 X-Google-Attributes: gid11508e,public X-Google-Language: ENGLISH,ASCII-7-bit From: "Paul at NCF" <notplmacca@clara.co.uk> Newsgroups: borland.public.cppbuilder.internet.socket References: <45d9e83a$1@newsgroups.borland.com> <45da1385@newsgroups.borland.com> <45da1b21$1@newsgroups.borland.com> Subject: Re: Passing info between threads Date: Tue, 20 Feb 2007 08:09:24 -0000 Lines: 58 X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2900.3028 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.3028 X-RFC2646: Format=Flowed; Response NNTP-Posting-Host: 86.133.178.47 Message-ID: <45daac91@newsgroups.borland.com> X-Trace: newsgroups.borland.com 1171958929 86.133.178.47 (20 Feb 2007 00:08:49 -0800) Path: arc1-ca.pugleaf.net!g2news2.google.com!news1.google.com!news3.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail