public inbox for pthreads-win32@sourceware.org
 help / color / mirror / Atom feed
* Re: Threading Issue - Program hangs on Ctrl-C - URGENT PLZ
@ 2003-10-18 15:09 jasvinder bajwa
  2003-10-20  4:59 ` amit mishra
  0 siblings, 1 reply; 4+ messages in thread
From: jasvinder bajwa @ 2003-10-18 15:09 UTC (permalink / raw)
  To: infoworldindia, pthreads-win32


Hi Amit,
In all your thread functions , you have statement do { } while(true) and 
trying to read from comm ports.
I guess you are looking for a graceful way of shutting down the threads.
i will suggest you to set a global variable something like timeToExit = 1;
change the condition to run the thread for ever to do { } while(timeToExit)
and when your applicaion catches Ctrl+C or any unwanted signal set the 
timeToExit to 0 which will cause all the threads to exit.

I guess it may solve the issue.
Thanks
Jas



>From: amit mishra <infoworldindia@yahoo.com>
>To: pthread <pthreads-win32@sources.redhat.com>
>Subject: Re: Threading Issue - Program hangs on Ctrl-C - URGENT PLZ
>Date: Fri, 17 Oct 2003 23:14:08 -0700 (PDT)
>
>Hi Ross,
>
>Thanks for the reply.
>I suppose the threads are not able to exit properly.
>Since all the threads are never going to terminate as
>it continues to read from respective COM ports, there
>should be some mechanism to end the thread gracefully.
>
>Could anyone give me sample code to test with for
>handling signals like Ctrl-C or to gracefully end the
>pthreads.
>
>Also, what should be the ideal mechanism for ending
>the threads when threads are continuosly running (i.e.
>its not going to terminate until some signal like
>Ctrl-C is given) ??
>
>Many Thanks
>Amit
>
>
>
>
>
>--- Ross Johnson <rpj@callisto.canberra.edu.au> wrote:
> > I don't have any direct experience in this area but
> > I believe exception
> > management in MT applications is tricky, so I
> > apologise in advance for
> > responding with questions.
> >
> > Questions:
> > What happens to the other threads when one thread
> > catches the exception
> > generated by ctrl-C?
> > What if the exception arrives while the thread holds
> > the mutex?
> >
> > Ross
> >
> > amit mishra wrote:
> >
> > >Hi,
> > >I had a simple serial port communication
> > application
> > >which uses pthread-win32 for threading.
> > >
> > >When the program exits, the application hangs and
> > the
> > >only way to recover is to restart the machine.
> > >
> > >I have debugged and the issue seems to be regarding
> > >thread handling or signal handling.
> > >
> > >Code snippet is given below for reference. Feel
> > free
> > >to ask for more information.
> > >
> > >Please reply asap.
> > >Many Thanks
> > >Amit
> > >--- CODE STARTS ------------------------------
> > >// all header files not shown
> > >
> > >#include "pthread.h"
> > >#include "signal.h"
> > >
> > >// three threads for each ports
> > >pthread_t t[3];
> > >int result = 0;
> > >int tid1, tid2, tid3;
> > >
> > >void* portOneFunc(void* arg);
> > >void* portTwoFunc(void* arg);
> > >void* portThreeFunc(void* arg);
> > >
> > >CDataOne* data1 = NULL;
> > >CDataTwo* data2 = NULL;
> > >CDataThree* data3 = NULL;
> > >
> > >// Custom Mutex class using pthread mutex
> > >CMyMutex myMutex;
> > >CWinApp theApp;
> > >
> > >//////////////////////////////////////////
> > >// Main
> > >//////////////////////////////////////////
> > >
> > >int _tmain(int argc, TCHAR* argv[], TCHAR* envp[])
> > >{
> > >// ---Initialize COMM Ports---
> > >CCommPort p1(RS_COM1);	// COM1
> > >CCommPort p2(RS_COM2);		// COM2
> > >CCommPort p3(RS_COM3);		// COM3
> > >
> > >// Init various Data Analyzers
> > >data1 = new CDataOne();
> > >data2 = new CDataTwo();
> > >data3 = new CDataThree();
> > >
> > >try {
> > >	// --------- Create Threads ------------
> > >	// Pthread Create
> > >	tid1 = pthread_create(
> > >		&t[0], NULL, portOneFunc, &p1);
> > >	tid2 = pthread_create(
> > >		&t[1], NULL, portTwoFunc, &p2);
> > >	tid3 = pthread_create(
> > >		&t[2], NULL, portThreeFunc, &p3);
> > >
> > >	// -------- Wait for Threads to complete ----
> > >	// Pthread Join
> > >	int ret = 0;
> > >
> > >	if (pthread_join(t[0], (void **) &result)) {
> > >		cout << "pthread join error" << endl;
> > >
> > >	}
> > >	if (pthread_join(t[1], (void **) &result)) {
> > >		cout << "pthread join error" << endl;
> > >	}
> > >	if (pthread_join(t[2], (void **) &result)) {
> > >		cout << "pthread join error" << endl;
> > >	}
> > >
> > >} PtW32CatchAll {
> > >	cerr << "ERROR : Thread Error" << endl;
> > >}
> > >
> > >delete data1;
> > >delete data2;
> > >delete data3;
> > >
> > >return 0;
> > >}
> > >
> > >
> > >//////////////////////////////////////////
> > >// Thread Functions
> > >//////////////////////////////////////////
> > >
> > >void* PortOneFunc(void* arg) {
> > >
> > >CCommPort *x_oPort1 = (CCommPort*)arg;
> > >
> > >try {
> > >   // Open Port with baudrate 4800
> > >   if (x_oPort1->Open(RS_4800)) {
> > >       	cout << "COM1 Opened" << endl;
> > >	do {
> > >	  // Get till terminating chars
> > >	  string str = x_oPort1->GetLine().c_str();
> > >myMutex.lock();				  // Append the data for further
> > >analysis
> > >	  data1->Append(str.c_str());
> > >	  myMutex.unlock();
> > >
> > >	} while(true);
> > >
> > >	  // Close the port
> > >	  x_oPort1->Close();
> > >	} else {
> > >	  cerr << "Error Opening COM 1 Port" << endl;
> > >	}
> > >} catch(...) {
> > >	cerr << "ERROR : Thread Exception" << endl;
> > >	//throw;
> > >}
> > >return (void*)true;
> > >}
> > >
> > >////////////////////////////////////////////
> > >void* PortTwoFunc(void* arg) {
> > >
> > >CCommPort *x_oPort2 = (CCommPort*)arg;
> > >
> > >try {
> > >	// Open Port
> > >	if (x_oPort2->Open(RS_1200)) {
> > >	  cout << "COM2 Opened" << endl;
> > >	  do {
> > >	     string str = x_oPort2->GetLine().c_str();
> > >	     myMutex.lock();
> > >	     data2->Append(str.c_str());
> > >	     myMutex.unlock();
> > >	  } while(true);
> > >	  x_oPort2->Close();
> > >	} else {
> > >   	cerr << "Error Opening COM 2 Port" << endl;
> > >	}
> > >} catch(...) {
> > >	cerr << "ERROR : Thread Exception" << endl;
> > >	//throw;
> > >}
> > >return (void*)true;
> > >}
> > >
> > >////////////////////////////////////////////
> > >void* PortThreeFunc(void* arg) {
> > >
> > >CCommPort *x_oPort3 = (CCommPort*)arg;
> > >
> > >try {
> > >   // Open Port
> > >   if (x_oPort3->Open(RS_1200)) {
> > >	cout << "COM3 Opened" << endl;
> > >	do {
> > >         string str = x_oPort3->GetLine().c_str();
> > >	 myMutex.lock();				 data3->Append(str.c_str());
> > >	 myMutex.unlock();
> > >	} while(true);
> > >	  x_oPort3->Close();
> > >   } else {
> > >	cerr << "Error Opening COM 3 Port" << endl;
> > >   }
> > >} catch(...) {
> > >   cerr << "ERROR : Thread Exception" << endl;
> > >   //throw;
> > >}
> > >
> > >return (void*)true;
> > >}
> > >-- CODE ENDS ------------------------------
> > >
> > >
> > >
> >
>=== message truncated ===
>
>
>__________________________________
>Do you Yahoo!?
>The New Yahoo! Shopping - with improved product search
>http://shopping.yahoo.com

_________________________________________________________________
Get 10MB of e-mail storage! Sign up for Hotmail Extra Storage.  
http://join.msn.com/?PAGE=features/es

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Threading Issue - Program hangs on Ctrl-C - URGENT PLZ
  2003-10-18 15:09 Threading Issue - Program hangs on Ctrl-C - URGENT PLZ jasvinder bajwa
@ 2003-10-20  4:59 ` amit mishra
  0 siblings, 0 replies; 4+ messages in thread
From: amit mishra @ 2003-10-20  4:59 UTC (permalink / raw)
  To: jasvinder bajwa, pthreads-win32

Hi,
Thanks Jasvinder for reply & suggestion.

After changing the optimization to "default" in MSVC++
project settings (Release Mode), the issue of computer
getting hanged has been resolved.

This is a KNOWN BUG :~ "Cancellation problems in
optimised code" 
http://sources.redhat.com/pthreads-win32/bugs.html

"I think the message of this section is that usage of
VCE version of pthreads in applications relying on
cancellation/cleanup AND using optimisations for   
creation of production code is highly unreliable for
the current version of the pthreads library."

Does it mean, I should use Win32 threads API rather
than pthread-win32 when optimization is highly
required ???

Regards,
Amit


--- jasvinder bajwa <jasvinder_bajwa9@hotmail.com>
wrote:
> 
> Hi Amit,
> In all your thread functions , you have statement do
> { } while(true) and 
> trying to read from comm ports.
> I guess you are looking for a graceful way of
> shutting down the threads.
> i will suggest you to set a global variable
> something like timeToExit = 1;
> change the condition to run the thread for ever to
> do { } while(timeToExit)
> and when your applicaion catches Ctrl+C or any
> unwanted signal set the 
> timeToExit to 0 which will cause all the threads to
> exit.
> 
> I guess it may solve the issue.
> Thanks
> Jas
> 
> 
> 
> >From: amit mishra <infoworldindia@yahoo.com>
> >To: pthread <pthreads-win32@sources.redhat.com>
> >Subject: Re: Threading Issue - Program hangs on
> Ctrl-C - URGENT PLZ
> >Date: Fri, 17 Oct 2003 23:14:08 -0700 (PDT)
> >
> >Hi Ross,
> >
> >Thanks for the reply.
> >I suppose the threads are not able to exit
> properly.
> >Since all the threads are never going to terminate
> as
> >it continues to read from respective COM ports,
> there
> >should be some mechanism to end the thread
> gracefully.
> >
> >Could anyone give me sample code to test with for
> >handling signals like Ctrl-C or to gracefully end
> the
> >pthreads.
> >
> >Also, what should be the ideal mechanism for ending
> >the threads when threads are continuosly running
> (i.e.
> >its not going to terminate until some signal like
> >Ctrl-C is given) ??
> >
> >Many Thanks
> >Amit
> >
> >
> >
> >
> >
> >--- Ross Johnson <rpj@callisto.canberra.edu.au>
> wrote:
> > > I don't have any direct experience in this area
> but
> > > I believe exception
> > > management in MT applications is tricky, so I
> > > apologise in advance for
> > > responding with questions.
> > >
> > > Questions:
> > > What happens to the other threads when one
> thread
> > > catches the exception
> > > generated by ctrl-C?
> > > What if the exception arrives while the thread
> holds
> > > the mutex?
> > >
> > > Ross
> > >
> > > amit mishra wrote:
> > >
> > > >Hi,
> > > >I had a simple serial port communication
> > > application
> > > >which uses pthread-win32 for threading.
> > > >
> > > >When the program exits, the application hangs
> and
> > > the
> > > >only way to recover is to restart the machine.
> > > >
> > > >I have debugged and the issue seems to be
> regarding
> > > >thread handling or signal handling.
> > > >
> > > >Code snippet is given below for reference. Feel
> > > free
> > > >to ask for more information.
> > > >
> > > >Please reply asap.
> > > >Many Thanks
> > > >Amit
> > > >--- CODE STARTS ------------------------------
> > > >// all header files not shown
> > > >
> > > >#include "pthread.h"
> > > >#include "signal.h"
> > > >
> > > >// three threads for each ports
> > > >pthread_t t[3];
> > > >int result = 0;
> > > >int tid1, tid2, tid3;
> > > >
> > > >void* portOneFunc(void* arg);
> > > >void* portTwoFunc(void* arg);
> > > >void* portThreeFunc(void* arg);
> > > >
> > > >CDataOne* data1 = NULL;
> > > >CDataTwo* data2 = NULL;
> > > >CDataThree* data3 = NULL;
> > > >
> > > >// Custom Mutex class using pthread mutex
> > > >CMyMutex myMutex;
> > > >CWinApp theApp;
> > > >
> > > >//////////////////////////////////////////
> > > >// Main
> > > >//////////////////////////////////////////
> > > >
> > > >int _tmain(int argc, TCHAR* argv[], TCHAR*
> envp[])
> > > >{
> > > >// ---Initialize COMM Ports---
> > > >CCommPort p1(RS_COM1);	// COM1
> > > >CCommPort p2(RS_COM2);		// COM2
> > > >CCommPort p3(RS_COM3);		// COM3
> > > >
> > > >// Init various Data Analyzers
> > > >data1 = new CDataOne();
> > > >data2 = new CDataTwo();
> > > >data3 = new CDataThree();
> > > >
> > > >try {
> > > >	// --------- Create Threads ------------
> > > >	// Pthread Create
> > > >	tid1 = pthread_create(
> > > >		&t[0], NULL, portOneFunc, &p1);
> > > >	tid2 = pthread_create(
> > > >		&t[1], NULL, portTwoFunc, &p2);
> > > >	tid3 = pthread_create(
> > > >		&t[2], NULL, portThreeFunc, &p3);
> > > >
> > > >	// -------- Wait for Threads to complete ----
> > > >	// Pthread Join
> > > >	int ret = 0;
> > > >
> > > >	if (pthread_join(t[0], (void **) &result)) {
> > > >		cout << "pthread join error" << endl;
> > > >
> > > >	}
> > > >	if (pthread_join(t[1], (void **) &result)) {
> > > >		cout << "pthread join error" << endl;
> > > >	}
> > > >	if (pthread_join(t[2], (void **) &result)) {
> > > >		cout << "pthread join error" << endl;
> > > >	}
> > > >
> > > >} PtW32CatchAll {
> > > >	cerr << "ERROR : Thread Error" << endl;
> > > >}
> > > >
> > > >delete data1;
> > > >delete data2;
> > > >delete data3;
> > > >
> > > >return 0;
> > > >}
> > > >
> > > >
> > > >//////////////////////////////////////////
> > > >// Thread Functions
> > > >//////////////////////////////////////////
> > > >
> > > >void* PortOneFunc(void* arg) {
> > > >
> > > >CCommPort *x_oPort1 = (CCommPort*)arg;
> > > >
> > > >try {
> > > >   // Open Port with baudrate 4800
> > > >   if (x_oPort1->Open(RS_4800)) {
> > > >       	cout << "COM1 Opened" << endl;
> > > >	do {
> > > >	  // Get till terminating chars
> > > >	  string str = x_oPort1->GetLine().c_str();
> > > >myMutex.lock();				  // Append the data for
> further
> > > >analysis
> > > >	  data1->Append(str.c_str());
> > > >	  myMutex.unlock();
> > > >
> > > >	} while(true);
> > > >
> 
=== message truncated ===


__________________________________
Do you Yahoo!?
The New Yahoo! Shopping - with improved product search
http://shopping.yahoo.com

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Threading Issue - Program hangs on Ctrl-C - URGENT PLZ
       [not found] <3F8EBDB9.9070706@callisto.canberra.edu.au>
@ 2003-10-18  6:14 ` amit mishra
  0 siblings, 0 replies; 4+ messages in thread
From: amit mishra @ 2003-10-18  6:14 UTC (permalink / raw)
  To: pthread

Hi Ross,

Thanks for the reply.
I suppose the threads are not able to exit properly.
Since all the threads are never going to terminate as
it continues to read from respective COM ports, there
should be some mechanism to end the thread gracefully.

Could anyone give me sample code to test with for
handling signals like Ctrl-C or to gracefully end the
pthreads.

Also, what should be the ideal mechanism for ending
the threads when threads are continuosly running (i.e.
its not going to terminate until some signal like
Ctrl-C is given) ??

Many Thanks 
Amit





--- Ross Johnson <rpj@callisto.canberra.edu.au> wrote:
> I don't have any direct experience in this area but
> I believe exception 
> management in MT applications is tricky, so I
> apologise in advance for 
> responding with questions.
> 
> Questions:
> What happens to the other threads when one thread
> catches the exception 
> generated by ctrl-C?
> What if the exception arrives while the thread holds
> the mutex?
> 
> Ross
> 
> amit mishra wrote:
> 
> >Hi,
> >I had a simple serial port communication
> application
> >which uses pthread-win32 for threading.
> >
> >When the program exits, the application hangs and
> the
> >only way to recover is to restart the machine.
> >
> >I have debugged and the issue seems to be regarding
> >thread handling or signal handling.
> >
> >Code snippet is given below for reference. Feel
> free
> >to ask for more information.
> >
> >Please reply asap. 
> >Many Thanks 
> >Amit
> >--- CODE STARTS ------------------------------
> >// all header files not shown
> >
> >#include "pthread.h"
> >#include "signal.h"
> >
> >// three threads for each ports
> >pthread_t t[3];		
> >int result = 0;
> >int tid1, tid2, tid3;
> >
> >void* portOneFunc(void* arg);
> >void* portTwoFunc(void* arg);
> >void* portThreeFunc(void* arg);
> >
> >CDataOne* data1 = NULL;
> >CDataTwo* data2 = NULL;
> >CDataThree* data3 = NULL;
> >
> >// Custom Mutex class using pthread mutex
> >CMyMutex myMutex; 
> >CWinApp theApp;
> >
> >//////////////////////////////////////////
> >// Main
> >//////////////////////////////////////////
> >
> >int _tmain(int argc, TCHAR* argv[], TCHAR* envp[])
> >{
> >// ---Initialize COMM Ports---
> >CCommPort p1(RS_COM1);	// COM1
> >CCommPort p2(RS_COM2);		// COM2
> >CCommPort p3(RS_COM3);		// COM3
> >
> >// Init various Data Analyzers
> >data1 = new CDataOne();			
> >data2 = new CDataTwo();	
> >data3 = new CDataThree();	
> >
> >try {
> >	// --------- Create Threads ------------
> >	// Pthread Create 		
> >	tid1 = pthread_create(
> >		&t[0], NULL, portOneFunc, &p1);
> >	tid2 = pthread_create(
> >		&t[1], NULL, portTwoFunc, &p2); 			
> >	tid3 = pthread_create(
> >		&t[2], NULL, portThreeFunc, &p3); 
> >			
> >	// -------- Wait for Threads to complete ----
> >	// Pthread Join
> >	int ret = 0;
> >
> >	if (pthread_join(t[0], (void **) &result)) {
> >		cout << "pthread join error" << endl;
> >		
> >	}
> >	if (pthread_join(t[1], (void **) &result)) {
> >		cout << "pthread join error" << endl;			
> >	}
> >	if (pthread_join(t[2], (void **) &result)) {
> >		cout << "pthread join error" << endl;			
> >	}
> >
> >} PtW32CatchAll {
> >	cerr << "ERROR : Thread Error" << endl;
> >} 
> >
> >delete data1;
> >delete data2;
> >delete data3;
> >
> >return 0;
> >}
> >
> >
> >//////////////////////////////////////////
> >// Thread Functions
> >//////////////////////////////////////////
> >
> >void* PortOneFunc(void* arg) {
> >	
> >CCommPort *x_oPort1 = (CCommPort*)arg;
> >
> >try {
> >   // Open Port with baudrate 4800
> >   if (x_oPort1->Open(RS_4800)) {			
> >       	cout << "COM1 Opened" << endl;
> >	do {				
> >	  // Get till terminating chars
> >	  string str = x_oPort1->GetLine().c_str();	 
> >myMutex.lock();				  // Append the data for further
> >analysis
> >	  data1->Append(str.c_str()); 
> >	  myMutex.unlock();
> >			
> >	} while(true);
> >	
> >	  // Close the port
> >	  x_oPort1->Close();
> >	} else {
> >	  cerr << "Error Opening COM 1 Port" << endl;
> >	}
> >} catch(...) {
> >	cerr << "ERROR : Thread Exception" << endl;
> >	//throw;
> >}
> >return (void*)true;
> >}
> >
> >////////////////////////////////////////////
> >void* PortTwoFunc(void* arg) {
> >
> >CCommPort *x_oPort2 = (CCommPort*)arg;
> >
> >try {
> >	// Open Port		
> >	if (x_oPort2->Open(RS_1200)) {		
> >	  cout << "COM2 Opened" << endl;
> >	  do {				
> >	     string str = x_oPort2->GetLine().c_str();
> >	     myMutex.lock();				
> >	     data2->Append(str.c_str());
> >	     myMutex.unlock();
> >	  } while(true);		
> >	  x_oPort2->Close();	
> >	} else {
> >   	cerr << "Error Opening COM 2 Port" << endl;
> >	}
> >} catch(...) {
> >	cerr << "ERROR : Thread Exception" << endl;
> >	//throw;
> >}
> >return (void*)true;
> >}
> >
> >////////////////////////////////////////////
> >void* PortThreeFunc(void* arg) {
> >
> >CCommPort *x_oPort3 = (CCommPort*)arg;
> >
> >try {
> >   // Open Port		
> >   if (x_oPort3->Open(RS_1200)) {		
> >	cout << "COM3 Opened" << endl;
> >	do {				
> >         string str = x_oPort3->GetLine().c_str();
> >	 myMutex.lock();				 data3->Append(str.c_str());
> >	 myMutex.unlock();
> >	} while(true);		
> >	  x_oPort3->Close();	
> >   } else {
> >	cerr << "Error Opening COM 3 Port" << endl;
> >   }
> >} catch(...) {
> >   cerr << "ERROR : Thread Exception" << endl;
> >   //throw;
> >}
> >
> >return (void*)true;
> >}
> >-- CODE ENDS ------------------------------
> >
> >
> >
> 
=== message truncated ===


__________________________________
Do you Yahoo!?
The New Yahoo! Shopping - with improved product search
http://shopping.yahoo.com

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Threading Issue - Program hangs on Ctrl-C - URGENT PLZ
@ 2003-10-16  5:21 amit mishra
  0 siblings, 0 replies; 4+ messages in thread
From: amit mishra @ 2003-10-16  5:21 UTC (permalink / raw)
  To: pthread

Hi,
I had a simple serial port communication application
which uses pthread-win32 for threading.

When the program exits, the application hangs and the
only way to recover is to restart the machine.

I have debugged and the issue seems to be regarding
thread handling or signal handling.

Code snippet is given below for reference. Feel free
to ask for more information.

Please reply asap. 
Many Thanks 
Amit
--- CODE STARTS ------------------------------
// all header files not shown

#include "pthread.h"
#include "signal.h"

// three threads for each ports
pthread_t t[3];		
int result = 0;
int tid1, tid2, tid3;

void* portOneFunc(void* arg);
void* portTwoFunc(void* arg);
void* portThreeFunc(void* arg);

CDataOne* data1 = NULL;
CDataTwo* data2 = NULL;
CDataThree* data3 = NULL;

// Custom Mutex class using pthread mutex
CMyMutex myMutex; 
CWinApp theApp;

//////////////////////////////////////////
// Main
//////////////////////////////////////////

int _tmain(int argc, TCHAR* argv[], TCHAR* envp[])
{
// ---Initialize COMM Ports---
CCommPort p1(RS_COM1);	// COM1
CCommPort p2(RS_COM2);		// COM2
CCommPort p3(RS_COM3);		// COM3

// Init various Data Analyzers
data1 = new CDataOne();			
data2 = new CDataTwo();	
data3 = new CDataThree();	

try {
	// --------- Create Threads ------------
	// Pthread Create 		
	tid1 = pthread_create(
		&t[0], NULL, portOneFunc, &p1);
	tid2 = pthread_create(
		&t[1], NULL, portTwoFunc, &p2); 			
	tid3 = pthread_create(
		&t[2], NULL, portThreeFunc, &p3); 
			
	// -------- Wait for Threads to complete ----
	// Pthread Join
	int ret = 0;

	if (pthread_join(t[0], (void **) &result)) {
		cout << "pthread join error" << endl;
		
	}
	if (pthread_join(t[1], (void **) &result)) {
		cout << "pthread join error" << endl;			
	}
	if (pthread_join(t[2], (void **) &result)) {
		cout << "pthread join error" << endl;			
	}

} PtW32CatchAll {
	cerr << "ERROR : Thread Error" << endl;
} 

delete data1;
delete data2;
delete data3;

return 0;
}


//////////////////////////////////////////
// Thread Functions
//////////////////////////////////////////

void* PortOneFunc(void* arg) {
	
CCommPort *x_oPort1 = (CCommPort*)arg;

try {
   // Open Port with baudrate 4800
   if (x_oPort1->Open(RS_4800)) {			
       	cout << "COM1 Opened" << endl;
	do {				
	  // Get till terminating chars
	  string str = x_oPort1->GetLine().c_str();	 
myMutex.lock();				  // Append the data for further
analysis
	  data1->Append(str.c_str()); 
	  myMutex.unlock();
			
	} while(true);
	
	  // Close the port
	  x_oPort1->Close();
	} else {
	  cerr << "Error Opening COM 1 Port" << endl;
	}
} catch(...) {
	cerr << "ERROR : Thread Exception" << endl;
	//throw;
}
return (void*)true;
}

////////////////////////////////////////////
void* PortTwoFunc(void* arg) {

CCommPort *x_oPort2 = (CCommPort*)arg;

try {
	// Open Port		
	if (x_oPort2->Open(RS_1200)) {		
	  cout << "COM2 Opened" << endl;
	  do {				
	     string str = x_oPort2->GetLine().c_str();
	     myMutex.lock();				
	     data2->Append(str.c_str());
	     myMutex.unlock();
	  } while(true);		
	  x_oPort2->Close();	
	} else {
   	cerr << "Error Opening COM 2 Port" << endl;
	}
} catch(...) {
	cerr << "ERROR : Thread Exception" << endl;
	//throw;
}
return (void*)true;
}

////////////////////////////////////////////
void* PortThreeFunc(void* arg) {

CCommPort *x_oPort3 = (CCommPort*)arg;

try {
   // Open Port		
   if (x_oPort3->Open(RS_1200)) {		
	cout << "COM3 Opened" << endl;
	do {				
         string str = x_oPort3->GetLine().c_str();
	 myMutex.lock();				 data3->Append(str.c_str());
	 myMutex.unlock();
	} while(true);		
	  x_oPort3->Close();	
   } else {
	cerr << "Error Opening COM 3 Port" << endl;
   }
} catch(...) {
   cerr << "ERROR : Thread Exception" << endl;
   //throw;
}

return (void*)true;
}
-- CODE ENDS ------------------------------







__________________________________
Do you Yahoo!?
The New Yahoo! Shopping - with improved product search
http://shopping.yahoo.com

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2003-10-20  4:59 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-10-18 15:09 Threading Issue - Program hangs on Ctrl-C - URGENT PLZ jasvinder bajwa
2003-10-20  4:59 ` amit mishra
     [not found] <3F8EBDB9.9070706@callisto.canberra.edu.au>
2003-10-18  6:14 ` amit mishra
  -- strict thread matches above, loose matches on Subject: below --
2003-10-16  5:21 amit mishra

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).