🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

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

Re: Passing info between threads

#1303
From: Lesley Anne
Date: Tue, 20 Feb 2007 16:39
50 lines
3557 bytes
"Paul at NCF" <notplmacca@clara.co.uk> wrote in message 
news:45da2a86@newsgroups.borland.com...
> Quick question:
>
> What components are you trying to use, and are you dropping them
> on the main form / instantiating them in the main form, or are you
> instantiating them in the 'worker' thread?  Or both?
>
> ie. I create say a UDP component in the thread and don't use it
> or reference it on the main form at all, that way I don't have
> to worry about the VCL components and VCL being non-thread safe
> (or using syncronize).

The worker thread handles all SCTP communications, while the VCL
thread handles everything else (which is primarily the GUI at the
moment).  There are no components for SCTP, just a library, but
that library is initialized and used exclusively from the SCTP
thread.

The thread is instantiated at application startup, and immediately
calls sctp_initLibrary() (which allocates a raw socket that will
be used in all communications, and does some other initializations
of library variables) and sctp_registerInstance() (which lets the
library know what functions to call for events, as well as things
like local addresses and port, and how many input and output
streams to use).  After that the thread calls sctp_eventLoop()
continually until Terminated.

The main VCL thread has to tell the SCTP thread when to make an
association (along with address and port parameters of where to
connect to), when to send a message (along with parameters for the
text of the message as well as which association to send it to),
and when to disconnect (along with a parameter for which
association to shut down).

When it makes a connection, the SCTP thread needs to tell the VCL
thread the ID for that association (so the VCL thread can use that
ID later to tell the SCTP thread where to send messages).  When it
receives a message from the far end, it has to send that message
to the VCL thread for processing (which in our test app is just a
matter of displaying it on the screen, but will eventually involve
more complex handling).  And there are various status messages it
passes back to the VCL thread as well for display/logging.

We're using Synchronize for everything passed from the SCTP thread
to the VCL thread, and critical sections around everything passed
from the VCL thread to the SCTP thread.  We've got it all working,
except that I'm not positive whether the way we pass things from
the VCL to SCTP threads will still work correctly when the events
fire more rapidly.
Technical Details
Message-ID: <45db2425@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!g2news2.google.com!news2.google.com!news1.google.com!newsfeed.media.kyoto-u.ac.jp!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mail
References: <45d9e83a$1@newsgroups.borland.com> <45da1385@newsgroups.borland.com> <45da1b21$1@newsgroups.borland.com> <45da2a86@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: "Lesley Anne" <mspfila (dash) brl (at) yahoo (dot) com>
Newsgroups: borland.public.cppbuilder.internet.socket
References: <45d9e83a$1@newsgroups.borland.com> <45da1385@newsgroups.borland.com> <45da1b21$1@newsgroups.borland.com> <45da2a86@newsgroups.borland.com>
Subject: Re: Passing info between threads
Date: Tue, 20 Feb 2007 11:39:35 -0500
Lines: 52
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: 144.160.5.25
Message-ID: <45db2425@newsgroups.borland.com>
X-Trace: newsgroups.borland.com 1171989541 144.160.5.25 (20 Feb 2007 08:39:01 -0800)
Path: arc1-ca.pugleaf.net!g2news2.google.com!news2.google.com!news1.google.com!newsfeed.media.kyoto-u.ac.jp!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mail