🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

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

Re: Multi-Thread Processing on Dual-Core CPU

#2337
From: Bob Gonder
Date: Wed, 14 Mar 2007 17:33
33 lines
2320 bytes
Robert G. Hoover wrote:

>When I set RXSize to 0 in my main thread/process, the fault occurs, I assume
>because it's fighting with the ReadFile() line below.

That doesn't sound like a very good idea.
For example:

>	ReadFile(hComm, &(RXBuffer[RXSize]),

RXSize is 1000
Start reading into RxBuffer[ 1000 ];
Main resets RXSize to 0
Read finishes 100 bytes

>		if (BytesRead)
>		{	RXSize += BytesRead;

RXSize is 100;
100 bytes are at RxBuffer[ 1000 ];
Who remembers those bytes?
Next read will take place at RxBuffer[100], not 0.

Other than CriticalSections, a nice way to keep order is to setup
pairs of variables.	V1 is read/writable by main, but read-only by
thread. V2 is read-only by main but read/writable by thread.

In this case, main would write I want you to read N bytes, and I have
read X bytes from your buffer.
Thread would write I have Y bytes avilable in the buffer at location
Z.

Likewise for TXSize. You have 2 threads modifying it.
Technical Details
Message-ID: <6gagv2h0947m95mrbferbjkrnt9ah27krs@4ax.com>
Path: arc1-ca.pugleaf.net!g2news1.google.com!news4.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
References: <45f57403@newsgroups.borland.com> <45f59433$1@newsgroups.borland.com> <45f5973e$1@newsgroups.borland.com> <45f598bf$1@newsgroups.borland.com> <45f59c41$1@newsgroups.borland.com> <45f59e8e$1@newsgroups.borland.com> <45f5aca4@newsgroups.borland.com> <45f5b4dc$1@newsgroups.borland.com> <45f5fdec$3@newsgroups.borland.com> <45f5fec6$1@newsgroups.borland.com> <45f81a06@newsgroups.borland.com>

Show Full Headers
Complete Article Headers
X-Google-Thread: 10cc67,411b13b57e2ea81a
X-Google-Attributes: gid10cc67,public
X-Google-Language: ENGLISH,ASCII-7-bit
From: Bob Gonder <notbg@notmindspring.invalid>
Newsgroups: borland.public.cppbuilder.nativeapi
Subject: Re: Multi-Thread Processing on Dual-Core CPU
Date: Wed, 14 Mar 2007 10:33:00 -0700
Organization: MindSpring Enterprises, Inc.
Reply-To: notbg@notmindspring.invalid
Message-ID: <6gagv2h0947m95mrbferbjkrnt9ah27krs@4ax.com>
References: <45f57403@newsgroups.borland.com> <45f59433$1@newsgroups.borland.com> <45f5973e$1@newsgroups.borland.com> <45f598bf$1@newsgroups.borland.com> <45f59c41$1@newsgroups.borland.com> <45f59e8e$1@newsgroups.borland.com> <45f5aca4@newsgroups.borland.com> <45f5b4dc$1@newsgroups.borland.com> <45f5fdec$3@newsgroups.borland.com> <45f5fec6$1@newsgroups.borland.com> <45f81a06@newsgroups.borland.com>
X-Newsreader: Forte Agent 1.93/32.576 English (American)
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
NNTP-Posting-Host: 67.77.145.18
X-Trace: newsgroups.borland.com 1173893579 67.77.145.18 (14 Mar 2007 10:32:59 -0800)
Lines: 36
Path: arc1-ca.pugleaf.net!g2news1.google.com!news4.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