473,405 Members | 2,421 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

Problem using IRIX 6.5 CC (MIPSPro C++) STL I/O w/ POSIX threads

After agonizing over this problem for a few days, I've decided to seek
help. No, not the variety that involes a jacket that zips up the back
but this august body of intrepid individuals.

I've discovered the following:
- My compile line should resemble:
CC -D_PTHREADS -D_POSIX_C_SOURCE=199506L -LANG:std -n32 -mips3 -c
<src> -o <obj>
- My link line should resemble:
CC -LANG:std -n32 -mips3 <objs> -o <executable> -lpthread
- the -D_POSIX_C_SOURCE=199506L specifies the supported version of the
POSIX standard
- the -D_PTHREADS is necessary to inform the MIPSPro C++ STL headers
that I intend to use pthreads and require them to use pthread
functions for locking purposes.

The problem is such:

I have written a simple test program that creates several threads.
Each pthread runs the same function: 1) it creates a
std::vector<std::string> and pushes several strings into the vector,
2) iterates over the vector printing its contents via std::cout, and
3) exits.

The problem that is occurring is that a simple line such as below

std::cout << "foo" << 1 << std::endl;

causes the program to crash.

Using Purify, I was able to determine that, for some oddball
reason, streaming an int to cout was the culprit. So then I begin to
play around...

std::cout << "foo" << '1' << std::endl; // works just fine

and..

std::cout << "foo" << std::endl; // also peachy keen

and...

std::cout << "foo" << 1L << std::endl; // same problem as the int

and also...

printf( "foo %d\n", 1); // this WORKS

I tested each of the above cases individually within my test app.
Every time that I said that it worked, I mean that the multithreaded
test application successfully ran to completion.

And, so, I am approaching wits end. I have run my same test
application on Solaris 2.9 using Sun Workshop C++ and it behaves just
fine. It's only with IRIX 6.5 MIPSPro C++ that I run into a problem.
It seems reasonably clear to me
that this problem is specific to MIPSPro C++ STL I/O and, perhaps, its
handling of pthreads. I haven't as yet attempted this same experiment
with SGI threads as I'm not especially interested in the results. I
only wrote this test case as I have a customer who needs our product
to support IRIX 6.5 32-bit mulithreaded.

I'm fairly certain that this is not a locking issue as some of the
above cases work run without any hiccups within my threads.

Help?

Evan
Jul 22 '05 #1
6 2201
In article <eb**************************@posting.google.com >,
Evan David Light <el****@acm.org> wrote:
After agonizing over this problem for a few days, I've decided to seek
help. No, not the variety that involes a jacket that zips up the back
but this august body of intrepid individuals.


You do give the CC command line (helpful).

You don't give any of
the MIPSpro compiler version involved
versions -b |grep ompil
the IRIX version involved (probably irrelevant, but which 6.5.x is it?)
a complete compileable and runnable test case.
(unless it's right there in front of me and I missed it...?)

Maybe someone can answer you without those, but I can't help
without them. Sorry.
David Anderson davea at sgi dot com
Jul 22 '05 #2
On 26 Nov 2003 07:42:14 -0800, el****@acm.org (Evan David Light)
wrote:
After agonizing over this problem for a few days, I've decided to seek
help. No, not the variety that involes a jacket that zips up the back
but this august body of intrepid individuals. The problem is such:

I have written a simple test program that creates several threads.
Each pthread runs the same function: 1) it creates a
std::vector<std::string> and pushes several strings into the vector,
2) iterates over the vector printing its contents via std::cout, and
3) exits.

The problem that is occurring is that a simple line such as below

std::cout << "foo" << 1 << std::endl;

causes the program to crash.
Typically, std::cout cannot be used from multiple threads without
locking. This is true of all streams objects in general. If you want
thread safety, either use printf, or lock accesses to the stream.

Using Purify, I was able to determine that, for some oddball
reason, streaming an int to cout was the culprit. So then I begin to
play around...

std::cout << "foo" << '1' << std::endl; // works just fine 1 2
Even if this happens to work, you might have another thread multiplex
output at 1 and/or 2.
and also...

printf( "foo %d\n", 1); // this WORKS
Usually printf provides the necessary locking in a thread-safe
library.
I tested each of the above cases individually within my test app.
Every time that I said that it worked, I mean that the multithreaded
test application successfully ran to completion.

And, so, I am approaching wits end. I have run my same test
application on Solaris 2.9 using Sun Workshop C++ and it behaves just
fine.
It is possible that this is because Solaris disables buffering of
std::cout.

It's only with IRIX 6.5 MIPSPro C++ that I run into a problem.It seems reasonably clear to me
that this problem is specific to MIPSPro C++ STL I/O and, perhaps, its
handling of pthreads. I haven't as yet attempted this same experiment
with SGI threads as I'm not especially interested in the results. I
only wrote this test case as I have a customer who needs our product
to support IRIX 6.5 32-bit mulithreaded.

I'm fairly certain that this is not a locking issue as some of the
above cases work run without any hiccups within my threads.


That's just because the successful methods don't happen to modify the
state of std::cout (they only call threadsafe methods of the
underlying C apis). If std::cout is unbuffered, then many calls won't
modify the state.

I'd recommend locking all accesses to std::cout. Using a locking proxy
class is the usual approach (it locks on creation, unlocks on exit).
e.g.

//use comma operator!
#define COUT (LockingProxy(mycout_mutex), std::cout)

COUT << "whatever" << 10 << std::endl; //proxy destructs here.

Tom

C++ FAQ: http://www.parashift.com/c++-faq-lite/
C FAQ: http://www.eskimo.com/~scs/C-faq/top.html
Jul 22 '05 #3
da***@quasar.engr.sgi.com (David Anderson) wrote in message news:<bq************@fido.engr.sgi.com>...
In article <eb**************************@posting.google.com >,
Evan David Light <el****@acm.org> wrote: You do give the CC command line (helpful).
Really? I wrote this above:
CC -D_PTHREADS -D_POSIX_C_SOURCE=199506L -LANG:std -n32 -mips3 -c
<src> -o <obj>

You don't give any of
the MIPSpro compiler version involved
versions -b |grep ompil
the IRIX version involved (probably irrelevant, but which 6.5.x is it?)
a complete compileable and runnable test case.
(unless it's right there in front of me and I missed it...?)


That's because I goofed and failed to cross post properly. See <a
href="http://groups.google.com/groups?hl=en&lr=&ie=UTF-8&oe=UTF-8&threadm=eb0e5592.0311260810.4414cb5%40posting.go ogle.com&rnum=17&prev=/groups%3Fq%3DSTL%2BMIPSPro%26start%3D10%26hl%3Den% 26lr%3D%26ie%3DUTF-8%26oe%3DUTF-8%26selm%3Deb0e5592.0311260810.4414cb5%2540posting .google.com%26rnum%3D17">here</a>
Jul 22 '05 #4
tom_usenet <to********@hotmail.com> wrote in message news:<vr********************************@4ax.com>. ..
I'd recommend locking all accesses to std::cout. Using a locking proxy
class is the usual approach (it locks on creation, unlocks on exit).
e.g.

//use comma operator!
#define COUT (LockingProxy(mycout_mutex), std::cout)

COUT << "whatever" << 10 << std::endl; //proxy destructs here.


For simplicity's sake, I did the sample

pthread_mutex_lock
cout << ...
pthread_mutex_unlock

around all of my couts and I still encountered the same problem.

Evan
Jul 22 '05 #5
In article <eb*************************@posting.google.com> ,
Evan David Light <el****@acm.org> wrote:
tom_usenet <to********@hotmail.com> wrote in message news:<vr********************************@4ax.com>. ..
I'd recommend locking all accesses to std::cout. Using a locking proxy
class is the usual approach (it locks on creation, unlocks on exit).
e.g.

//use comma operator!
#define COUT (LockingProxy(mycout_mutex), std::cout)

COUT << "whatever" << 10 << std::endl; //proxy destructs here.


For simplicity's sake, I did the sample

pthread_mutex_lock
cout << ...
pthread_mutex_unlock

around all of my couts and I still encountered the same problem.


MIPSpro7.3 is now quite old (released May 1999).
7.3.1.1,7.3.1.2, 7.3.1.3, 7.4, 7.4.1 followed it.
(7.4.1 released June 2003). I would suggest 7.4.1 as the
best choice available today.
uname -R
versions -b |grep ompil
would give the versions info that would mean most to me,
but that's not going to help, I'm afraid, given that
you're unable to supply a compileable runable test case
(if you did so, I've been unable to find it) so no one can
really verify that any particular release fixes the problem.

Even the original thread in comp.programming.threads does
not seem to have a complete test case.

Have you tried creating a small test case, using pthreads
and cout, to see if you reproduce the problem?

David Anderson
Jul 22 '05 #6
In article <bq************@fido.engr.sgi.com>,
David Anderson <da***@quasar.engr.sgi.com> wrote:
Have you tried creating a small test case, using pthreads
and cout, to see if you reproduce the problem?

Evan Light provided a test case, which I have simplfied slightly.
pth2.cxx:
#include <iostream>
int
main()
{
std::cout << 1 << std::endl;
}

Makefile:
pth2: pth2.cxx
CC -D_PTHREADS -D_POSIX_C_SOURCE=199506L -LANG:std \
-n32 -mips3 pth2.cxx -o pth2a
CC -D_POSIX_C_SOURCE=199506L -LANG:std \
-n32 -mips3 pth2.cxx -o pth2b
pth2a crashes (segv). pth2b runs ok, printing
test1 <newline>

The -D_PTHREADS is provoking the crash.

This with 7.4.1, IRIX 6.5.22.
With earlier IRIX this may not compile (you get complaints
about some scanf stuff).

I'll see this gets looked into and keep you informed.
I created bug 905611 to track this issue.
Sorry about this, rather looks like our bug.
David Anderson

Jul 22 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Bram Stolk | last post by:
Hi there, I just built and installed Python-2.4.1 on my Irix machine. My compiler, the MipsPro compiler, chokes on the Python.h include file, as demonstrated here: $ CC -v MIPSpro...
2
by: Nicolas GALAN | last post by:
Hello, I've a problem about templates which occurs on g++ and not with CC on Irix. g++ says : Test.cpp: In member function `void A::test()': Test.cpp:53: error: parse error before `>' token ...
3
by: Nomak | last post by:
Hello, i've lost about hours (at least) to find a problem. I use the following utility function: 13 template <typename T> 14 inline 15 T 16 diffabs(T a, T b) 17 {
0
by: Abhishek | last post by:
Hi, I have an OLD C++ application that I am trying to port using the new C++ STL (standard library template) across several platforms. While I have been succcessful in building the application...
3
by: Roger Davis | last post by:
I am trying to use nothrow new() and am encountering what seems to be a bug in the SGI/Irix C++ environment. The following program runs OK under Solaris and Linux, but dumps core at the delete...
0
by: Xiao Jianfeng | last post by:
Hello, I'm trying to build python2.4.2 on IRIX6.5(cc version MIPSpro Compilers: Version 7.3.1.3m). But the socket module failed to compile. I found this in ./Modules/socketmodule.c, line 193:...
39
by: elnanni | last post by:
I've a problem in the use of threads, they don't work as i want them to. Here's the code, the problem is that if i uncomment the //pthread_join(thread_ID, NULL);, the main program stops until the...
3
by: vaddadi.chandu | last post by:
I am writing a multithreaded web-server and multithreaded client in C. The server is required to keep a log of the transactions in a local file. I try to open a file using the following: FILE...
11
by: kolmogolov | last post by:
hi, it's not really an endian problem. I think I must be missing something else ... The problem can be reduced to different results of the following two segments of codes: (cut and pasted...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.