🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

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

Multi-Thread Processing on Dual-Core CPU

#2334
From: Robert G. Hoover
Date: Wed, 14 Mar 2007 15:51
75 lines
3892 bytes
Hi Jon,

Yep, that did the trick. Makes sense, I suppose if you ignore the "MM_TEXT"
description???  ;)


As this thread has been incredibly helpful for my understanding of multi-thread
parallel processing, I'd like to throw another log on the fire....

I'm now realizing how little I know about multi-thread processing as my other
threads in my program are crashing out. For example, my commport listening
thread causes a program fault when I change the value of the indexing variable.
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. This code has no
semaphores in it at all. If I place simple bool variables like 'busy' and
'waiting' into the code, will I run into the same problem, accessing the bool
variables from both sides at once? Is this a good case for the Win32 Semaphore
functions? Are they overkill for this little thing? My experience is very
limited because I never had this problem with single-processor systems, and of
course this code functions with no problem on my older machines. But the
dual-core.... no dice. :(

Thanks,

Rob

_____________________________________________________________

void CommPortClass::TransferThread()
{
	// log event
	Global_UpdateStatusPrivate(String("entering ") + __FUNC__ + "()...");

	// set semiphore
	ThreadTerminated = false;
	ThreadFinished   = false;

	// listen for incoming data, transfer outgoing data as needed
	while (!ThreadTerminated)
	{
		// number of bytes read from port
		DWORD BytesRead;

		// read from port in case data is coming in
		ReadFile(hComm, &(RXBuffer[RXSize]),
                         RXBufferLength - RXSize, BytesRead, NULL);

		// check for incoming data
		if (BytesRead)
		{
			// increase buffer count to reflect presence of new data
			RXSize += BytesRead;
		}

		// check for data to write
		if (TXSize)
		{
			// number of bytes written to port
			DWORD BytesOut;

			// write data to commport
			::WriteFile(hComm, TXBuffer, TXSize, &BytesOut, NULL);

			// decrement buffer count to reflect transfer of data
			TXSize -= BytesOut;
		}
	}

	// clear semaphore - allow class to exit
	ThreadFinished = true;

	// log event
	Global_UpdateStatusPrivate(String("exiting ") + __FUNC__ + "()...");
}
//---------------------------------------------------------------------------
Technical Details
Message-ID: <45f81a06@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!g2news1.google.com!news3.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!newsfeed00.sul.t-online.de!t-online.de!newsfeed.freenet.de!news.albasani.net!feeder06.uucp-net.de!reader.uucp.at!newsfeed.uucp.at!news.uucp.at!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>

Show Full Headers
Complete Article Headers
X-Google-Thread: 10cc67,411b13b57e2ea81a
X-Google-Attributes: gid10cc67,public
X-Google-Language: ENGLISH,ASCII-7-bit
Date: Wed, 14 Mar 2007 11:51:18 -0400
From: "Robert G. Hoover" <not.a.real.address@anywhere.sorry>
User-Agent: Thunderbird 1.5.0.10 (Windows/20070221)
MIME-Version: 1.0
Newsgroups: borland.public.cppbuilder.nativeapi
Subject: Multi-Thread Processing on Dual-Core CPU
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>
In-Reply-To: <45f5fec6$1@newsgroups.borland.com>
X-Enigmail-Version: 0.94.1.0
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit
X-Antivirus: avast! (VPS 000723-1, 03/12/2007), Outbound message
X-Antivirus-Status: Not-Tested
NNTP-Posting-Host: 67.142.36.34
Message-ID: <45f81a06@newsgroups.borland.com>
X-Trace: newsgroups.borland.com 1173887494 67.142.36.34 (14 Mar 2007 08:51:34 -0800)
Lines: 75
Path: arc1-ca.pugleaf.net!g2news1.google.com!news3.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!newsfeed00.sul.t-online.de!t-online.de!newsfeed.freenet.de!news.albasani.net!feeder06.uucp-net.de!reader.uucp.at!newsfeed.uucp.at!news.uucp.at!newsgroups.borland.com!not-for-mail