| Author | 
		  Message
		 | 
		
		  | zealotcat | 
		  
		    
			  
				 Posted: Thu Feb 26, 2004 10:51 am    Post subject: Multi-thread! | 
				     | 
			   
			 
		   | 
		
		
		   Novice
 
 Joined: 25 Feb 2004 Posts: 12
  
  | 
		  
		    
			  
				I write a multi-thread application on RedHat 9(g++3.2.2) using Imq* C++ wrapper class. It can complie and link,but can not running.It exit at Line:"if( qmgr.connect() )". Why?
 
Who has some document or sample about multi-thread applicaton using Imq*? Thx!
 
*********************************************************
 
#include <iostream>
 
#include <pthread.h>
 
 
#define STREAM  "SAMPLE.BROKER.RESULTS.STREAM"
 
#define TOPIC   "Sport/Soccer/Event/"
 
 
using namespace std;
 
typedef unsigned char uchar;
 
 
void * pub_thread( void* arg )
 
{
 
    ImqQueue queue;
 
    ImqQueueManager qmgr;
 
 
    qmgr.setConnectOptions( MQCNO_HANDLE_SHARE_BLOCK );
 
    if( qmgr.connect() )
 
    {
 
        cout << "OK" << endl;
 
    }
 
    else
 
    {
 
        cout << "FAILED" << endl;
 
    }
 
    return 0;
 
}
 
 
int main()
 
{
 
    pthread_t tid;
 
    pthread_create( &tid, NULL, pub_thread, ( void* )&qmgr );
 
    return 0;
 
} | 
			   
			 
		   | 
		
		
		  | Back to top | 
		  
		  	
		   | 
		
		
		    | 
		
		
		  | jefflowrey | 
		  
		    
			  
				 Posted: Thu Feb 26, 2004 11:27 am    Post subject: Re: Multi-thread! | 
				     | 
			   
			 
		   | 
		
		
		   Grand Poobah
 
 Joined: 16 Oct 2002 Posts: 19981
  
  | 
		  
		    
			  
				
   
	| zealotcat wrote: | 
   
  
	It exit at Line:"if( qmgr.connect() )". Why?
 
 | 
   
 
 
You tell us.
 
 
What exception is being thrown?  what error messages are being generated and logged?
 
 
   
	| zealotcat wrote: | 
   
  
	| Who has some document or sample about multi-thread applicaton using Imq*?  | 
   
 
 
I think the button at the top of this page that says 'documentation' may help. _________________ I am *not* the model of the modern major general. | 
			   
			 
		   | 
		
		
		  | Back to top | 
		  
		  	
		   | 
		
		
		    | 
		
		
		  | zealotcat | 
		  
		    
			  
				 Posted: Thu Feb 26, 2004 9:15 pm    Post subject:  | 
				     | 
			   
			 
		   | 
		
		
		   Novice
 
 Joined: 25 Feb 2004 Posts: 12
  
  | 
		  
		    
			  
				| It exit without any exception and reason code !!! | 
			   
			 
		   | 
		
		
		  | Back to top | 
		  
		  	
		   | 
		
		
		    | 
		
		
		  | jefflowrey | 
		  
		    
			  
				 Posted: Fri Feb 27, 2004 4:14 am    Post subject:  | 
				     | 
			   
			 
		   | 
		
		
		   Grand Poobah
 
 Joined: 16 Oct 2002 Posts: 19981
  
  | 
		  
		    
			  
				
   
	| zealotcat wrote: | 
   
  
	| It exit without any exception and reason code !!! | 
   
 
 
The code you posted didn't catch any exceptions, or capture any reason codes. _________________ I am *not* the model of the modern major general. | 
			   
			 
		   | 
		
		
		  | Back to top | 
		  
		  	
		   | 
		
		
		    | 
		
		
		  | clindsey | 
		  
		    
			  
				 Posted: Fri Feb 27, 2004 6:04 am    Post subject:  | 
				     | 
			   
			 
		   | 
		
		
		   Knight
 
 Joined: 12 Jul 2002 Posts: 586 Location: Dallas, Tx 
  | 
		  
		    
			  
				Take a look at one of the mq c++ samples to see how error reporting is done. For example, this is a snippet from /opt/mqm/samp/imqsput.cpp
 
 
   
	| Code: | 
   
  
	
 
  if ( ! mgr.connect( ) ) {
 
 
    /* stop if it failed */
 
    printf( "ImqQueueManager::connect ended with reason code %d\n",
 
            (int)mgr.reasonCode( ) );
 
    exit( (int)mgr.reasonCode( ) );
 
  }
 
 | 
   
 
 
 
The odds are pretty good that you will see a reasonCode of 2059.
 
From an earlier post, you indicated you are linking with the client libraries. 
 
You will find hundreds of others posts that give suggestions for a client connect that fails with 2059.... e.g no listener, MQSERVER not set, etc. But first, you have to know for sure it is failing with 2059.
 
 
Charlie | 
			   
			 
		   | 
		
		
		  | Back to top | 
		  
		  	
		   | 
		
		
		    | 
		
		
		  | zealotcat | 
		  
		    
			  
				 Posted: Fri Feb 27, 2004 7:06 am    Post subject:  | 
				     | 
			   
			 
		   | 
		
		
		   Novice
 
 Joined: 25 Feb 2004 Posts: 12
  
  | 
		  
		    
			  
				Sorry,all!
 
The application exit unexpectedly at line:
 
 
if ( ! mgr.connect( ) ) 
 
 
and following line can not excute, that is, it will not output "OK" or "FAILED"!
 
 
If I use single-thread,it work well! | 
			   
			 
		   | 
		
		
		  | Back to top | 
		  
		  	
		   | 
		
		
		    | 
		
		
		  | clindsey | 
		  
		    
			  
				 Posted: Fri Feb 27, 2004 7:48 am    Post subject:  | 
				     | 
			   
			 
		   | 
		
		
		   Knight
 
 Joined: 12 Jul 2002 Posts: 586 Location: Dallas, Tx 
  | 
		  
		    
			  
				In that case, make sure you are linking with mq's thread safe libraries and also with c runtime thread safe libs as well.
 
 
Charlie | 
			   
			 
		   | 
		
		
		  | Back to top | 
		  
		  	
		   | 
		
		
		    | 
		
		
		  | zealotcat | 
		  
		    
			  
				 Posted: Fri Feb 27, 2004 8:53 am    Post subject:  | 
				     | 
			   
			 
		   | 
		
		
		   Novice
 
 Joined: 25 Feb 2004 Posts: 12
  
  | 
		  
		    
			  
				I link these library:
 
LIBS = -limqb23gl_r -limqc23gl_r | 
			   
			 
		   | 
		
		
		  | Back to top | 
		  
		  	
		   | 
		
		
		    | 
		
		
		  | gunter | 
		  
		    
			  
				 Posted: Fri Feb 27, 2004 12:41 pm    Post subject:  | 
				     | 
			   
			 
		   | 
		
		
		   Partisan
 
 Joined: 21 Jan 2004 Posts: 307 Location: Germany, Frankfurt 
  | 
		  
		    
			  
				There are a few problems with MQ and RedHat 9, the basic cause are threads. Maybe you have the same problem. Try LD_ASSUME_KERNEL=2.2.5 and/or search "Redhat 9 and MQ" on this site and in google, you will find a lot of hints.
 
 
If you publish code in the discussion, please do it without mistakes. Your code may not compile. 
 
- no include for MQ
 
- qmgr is not defined in main | 
			   
			 
		   | 
		
		
		  | Back to top | 
		  
		  	
		   | 
		
		
		    | 
		
		
		  | zealotcat | 
		  
		    
			  
				 Posted: Sat Feb 28, 2004 4:22 am    Post subject:  | 
				     | 
			   
			 
		   | 
		
		
		   Novice
 
 Joined: 25 Feb 2004 Posts: 12
  
  | 
		  
		    
			  
				I try these code on OS redhat 8 and it exit too!
 
Code:
 
***********************************************************
 
   
	| Code: | 
   
  
	#include <iostream>
 
#include <imqi.hpp>
 
#include <pthread.h>
 
 
#define STREAM "SAMPLE.BROKER.RESULTS.STREAM"
 
#define TOPIC "Sport/Soccer/Event/"
 
 
using namespace std;
 
typedef unsigned char uchar;
 
 
void * pub_thread( void* arg )
 
{
 
ImqQueue queue;
 
ImqQueueManager qmgr;
 
 
qmgr.setConnectOptions( MQCNO_HANDLE_SHARE_BLOCK );
 
if( qmgr.connect() )
 
{
 
cout << "OK" << endl;
 
}
 
else
 
{
 
cout << "FAILED" << endl;
 
}
 
return 0;
 
}
 
 
int main()
 
{
 
pthread_t tid;
 
pthread_create( &tid, NULL, pub_thread, NULL );
 
return 0;
 
} | 
   
 
 | 
			   
			 
		   | 
		
		
		  | Back to top | 
		  
		  	
		   | 
		
		
		    | 
		
		
		  | gunter | 
		  
		    
			  
				 Posted: Sat Feb 28, 2004 5:53 am    Post subject:  | 
				     | 
			   
			 
		   | 
		
		
		   Partisan
 
 Joined: 21 Jan 2004 Posts: 307 Location: Germany, Frankfurt 
  | 
		  
		    
			  
				Only a suggestion, I tried it with one thread an it works:
 
 
In MQ 5.3 connections are tread-save. You can connect in main and use it in all threads. 
 
 
I don't know why your code doesn't work, but If you make a connection that will not be shared, it's not nessesary to set MQCNO_HANDLE_SHARE_BLOCK. | 
			   
			 
		   | 
		
		
		  | Back to top | 
		  
		  	
		   | 
		
		
		    | 
		
		
		  | JasonE | 
		  
		    
			  
				 Posted: Sat Feb 28, 2004 8:23 am    Post subject:  | 
				     | 
			   
			 
		   | 
		
		
		   Grand Master
 
 Joined: 03 Nov 2003 Posts: 1220 Location: Hursley 
  | 
		  
		    
			  
				
   
	| Quote: | 
   
  
	In MQ 5.3 connections are tread-save. You can connect in main and use it in all threads. 
 
 
I don't know why your code doesn't work, but If you make a connection that will not be shared, it's not nessesary to set MQCNO_HANDLE_SHARE_BLOCK | 
   
 
 
 
Except in the .NET layer, this isnt true - By default, each thread needs its own HConn, and they cant be shared across threads. To make this happen you need to specify one of the MQCNO_HANDLE_SHARE_* options, in which case the returned handle CAN be used on any thread | 
			   
			 
		   | 
		
		
		  | Back to top | 
		  
		  	
		   | 
		
		
		    | 
		
		
		  | zealotcat | 
		  
		    
			  
				 Posted: Sat Feb 28, 2004 8:43 am    Post subject:  | 
				     | 
			   
			 
		   | 
		
		
		   Novice
 
 Joined: 25 Feb 2004 Posts: 12
  
  | 
		  
		    
			  
				
   
	| gunter wrote: | 
   
  
	Only a suggestion, I tried it with one thread an it works:
 
 
In MQ 5.3 connections are tread-save. You can connect in main and use it in all threads. 
 
 
I don't know why your code doesn't work, but If you make a connection that will not be shared, it's not nessesary to set MQCNO_HANDLE_SHARE_BLOCK. | 
   
 
 
Refers to <<WebSphere MQ Using C++>>:
 
For a multithreaded program, each thread must use a separate
 
ImqQueueManager object. Connections in different threads have different
 
MQHCONN connection handles.
 
 
So I think the ImqQueueManager is not thread safe!
 
By the way, this code can not run normally on win2000,too. | 
			   
			 
		   | 
		
		
		  | Back to top | 
		  
		  	
		   | 
		
		
		    | 
		
		
		  | gunter | 
		  
		    
			  
				 Posted: Sun Feb 29, 2004 12:15 am    Post subject:  | 
				     | 
			   
			 
		   | 
		
		
		   Partisan
 
 Joined: 21 Jan 2004 Posts: 307 Location: Germany, Frankfurt 
  | 
		  
		    
			  
				You are right, the Connection is save, the ImqQueueManager is not save.  The manual is from 2002,  it's older than MQ 5.3, but you can't look in the code. 
 
I bet your problems are related to MQSeries C++ and not to MQI. I would prefer using MQI because:- less dependencies
 
- less restrictions 
 
- more control
 
- better support from the community, if you have a problem
 
 I can't see any atvantage in using MQSeries C++. Write your own MQ classes with only featueres you need. | 
			   
			 
		   | 
		
		
		  | Back to top | 
		  
		  	
		   | 
		
		
		    | 
		
		
		  | 
		    
		   |