ASG
IBM
Zystems
Cressida
Icon
Netflexity
 
  MQSeries.net
Search  Search       Tech Exchange      Education      Certifications      Library      Info Center      SupportPacs      LinkedIn  Search  Search                                                                   FAQ  FAQ   Usergroups  Usergroups
 
Register  ::  Log in Log in to check your private messages
 
RSS Feed - WebSphere MQ Support RSS Feed - Message Broker Support

MQSeries.net Forum Index » IBM MQ API Support » Multi-thread!

Post new topic  Reply to topic
 Multi-thread! « View previous topic :: View next topic » 
Author Message
zealotcat
PostPosted: Thu Feb 26, 2004 10:51 am    Post subject: Multi-thread! Reply with quote

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
View user's profile Send private message
jefflowrey
PostPosted: Thu Feb 26, 2004 11:27 am    Post subject: Re: Multi-thread! Reply with quote

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
View user's profile Send private message
zealotcat
PostPosted: Thu Feb 26, 2004 9:15 pm    Post subject: Reply with quote

Novice

Joined: 25 Feb 2004
Posts: 12

It exit without any exception and reason code !!!
Back to top
View user's profile Send private message
jefflowrey
PostPosted: Fri Feb 27, 2004 4:14 am    Post subject: Reply with quote

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
View user's profile Send private message
clindsey
PostPosted: Fri Feb 27, 2004 6:04 am    Post subject: Reply with quote

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
View user's profile Send private message
zealotcat
PostPosted: Fri Feb 27, 2004 7:06 am    Post subject: Reply with quote

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
View user's profile Send private message
clindsey
PostPosted: Fri Feb 27, 2004 7:48 am    Post subject: Reply with quote

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
View user's profile Send private message
zealotcat
PostPosted: Fri Feb 27, 2004 8:53 am    Post subject: Reply with quote

Novice

Joined: 25 Feb 2004
Posts: 12

I link these library:
LIBS = -limqb23gl_r -limqc23gl_r
Back to top
View user's profile Send private message
gunter
PostPosted: Fri Feb 27, 2004 12:41 pm    Post subject: Reply with quote

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
View user's profile Send private message
zealotcat
PostPosted: Sat Feb 28, 2004 4:22 am    Post subject: Reply with quote

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
View user's profile Send private message
gunter
PostPosted: Sat Feb 28, 2004 5:53 am    Post subject: Reply with quote

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
View user's profile Send private message
JasonE
PostPosted: Sat Feb 28, 2004 8:23 am    Post subject: Reply with quote

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
View user's profile Send private message
zealotcat
PostPosted: Sat Feb 28, 2004 8:43 am    Post subject: Reply with quote

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
View user's profile Send private message
gunter
PostPosted: Sun Feb 29, 2004 12:15 am    Post subject: Reply with quote

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
View user's profile Send private message
Display posts from previous:   
Post new topic  Reply to topic Page 1 of 1

MQSeries.net Forum Index » IBM MQ API Support » Multi-thread!
Jump to:  



You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
Protected by Anti-Spam ACP
 
 


Theme by Dustin Baccetti
Powered by phpBB © 2001, 2002 phpBB Group

Copyright © MQSeries.net. All rights reserved.