🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.cppbuilder.internet.socket
Article #1238

Re: Passing info between threads

#1238
From: Paul at NCF
Date: Thu, 22 Feb 2007 22:46
56 lines
3723 bytes
Hi,

I may have lost the plot, but I thought you wanted to pass information to a 
(secondary) thread from the main VCL thread (mainform)?

> Wouldn't that defeat the purpose?  In order for the queue to protect the 
> two threads from each other, it needs to bridge the gap between the two. 
> If my thread puts the message into the queue itself, and then later takes 
> it off, then what's the queue there for?

If you call the threads AddCommand method to add to the queue, the main VCL 
thread is running and calling into the thread.  So the VCL thread is adding 
to the queue.  The thread could then get signaled and woken up, and remove 
the item off the queue.

> That looks to me like it adds the command in the main form, but then calls 
> the sctp thread to handle it.

Yes, thats what the example looked like that you showed?

> Isn't that just what it's doing here?  The first line above adds the 
> command, then the second line tells the thread there's a command for it to 
> handle.

Not sure it did.  Looked to me like the VCL thread added the command to the 
queue, and then calls the threads handle command to take it off the queue 
and process it?

> I don't want the thread to sleep, because some of the applications I use 
> this for may be handling high traffic volumes, and I don't want to slow 
> down performance by blocking the communication library.  The while loop in 
> the thread's Execute function looks like this right now:

Yes, I wouldn't do that normally, I was suggesting it to get something 
basically working without setting up the signalling and wait for objects 
API.

> If I could easily check whether there's anything in the queue, then maybe 
> I could add a line here (so that it alternates with the library's 
> sctp_eventLoop function) to check for any commands it has pending. 
> However, even seeing whether the TThreadList is empty or not requires 
> locking it first.  If this thread keeps continually locking the list (even 
> when there's nothing there), would the main thread have a harder time 
> getting its own lock when it wants to add something?  I prefer for the 
> main unit to tell the thread when there's a command in the list for it to 
> handle.  That way, the thread would only need to lock the list when it's 
> retrieving a command off of it.

WaitForMultipleObjects would only wake up the thread when something was 
signalled.  And it would only block the VCL thread when it was locked, and 
vv.

As I said, I may have lost the plot and be completely misunderstanding what 
you are trying to do.

Paul
Technical Details
Message-ID: <45de1d0f@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!g2news2.google.com!news2.google.com!news3.google.com!news.glorb.com!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mail
References: <45d9e83a$1@newsgroups.borland.com> <h21mt21bg7maqp25d2lqkr9b1iet0eu3g6@4ax.com> <45db2486$1@newsgroups.borland.com> <vj8nt2llf7deda6ioqggci4rds885qcmne@4ax.com> <45dcc0cb@newsgroups.borland.com> <45dd557c$1@newsgroups.borland.com> <45ddf727@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> <h21mt21bg7maqp25d2lqkr9b1iet0eu3g6@4ax.com> <45db2486$1@newsgroups.borland.com> <vj8nt2llf7deda6ioqggci4rds885qcmne@4ax.com> <45dcc0cb@newsgroups.borland.com> <45dd557c$1@newsgroups.borland.com> <45ddf727@newsgroups.borland.com>
Subject: Re: Passing info between threads
Date: Thu, 22 Feb 2007 22:46:16 -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.132.248.44
Message-ID: <45de1d0f@newsgroups.borland.com>
X-Trace: newsgroups.borland.com 1172184335 86.132.248.44 (22 Feb 2007 14:45:35 -0800)
Path: arc1-ca.pugleaf.net!g2news2.google.com!news2.google.com!news3.google.com!news.glorb.com!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mail