Board index » cppbuilder » Multi-Thread Processing on Dual-Core CPU
Robert G. Hoover
![]() CBuilder Developer |
Multi-Thread Processing on Dual-Core CPU2007-03-14 11:51:18 PM cppbuilder68 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__ + "()..."); } //--------------------------------------------------------------------------- |