473,854 Members | 1,765 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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_SOURC E=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_SOURC E=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 2232
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<st d::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(m ycout_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.en gr.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_SOURC E=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.c om/groups?hl=en&lr =&ie=UTF-8&oe=UTF-8&threadm=eb0e5 592.0311260810. 4414cb5%40posti ng.google.com&r num=17&prev=/groups%3Fq%3DST L%2BMIPSPro%26s tart%3D10%26hl% 3Den%26lr%3D%26 ie%3DUTF-8%26oe%3DUTF-8%26selm%3Deb0e 5592.0311260810 .4414cb5%2540po sting.google.co m%26rnum%3D17"> here</a>
Jul 22 '05 #4
tom_usenet <to********@hot mail.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(m ycout_mutex), std::cout)

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


For simplicity's sake, I did the sample

pthread_mutex_l ock
cout << ...
pthread_mutex_u nlock

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

Evan
Jul 22 '05 #5
In article <eb************ *************@p osting.google.c om>,
Evan David Light <el****@acm.org > wrote:
tom_usenet <to********@hot mail.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(m ycout_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.programmin g.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.e ngr.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_SOURC E=199506L -LANG:std \
-n32 -mips3 pth2.cxx -o pth2a
CC -D_POSIX_C_SOURC E=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
1605
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 Compilers: Version 7.41 $ python -V
2
310
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 Versions of g++ : 2.96 and 3.3.3
3
2345
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
1064
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 on several platforms, I have not been able to successfully build it on IRIX (SGI). I even tried to compile it using the option -LANG:std and the define _STLP_USE_OWN_NAMESPACE. But I still get the error. The most common error is - cc-1070 CC:...
3
2490
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 statement under Irix. Is this really an SGI implementation bug, or have I done something stupid? (Other than trying to use nothrow new(), that is ;-) ) #include <new> #include <stdexcept>
0
865
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: -------------------------------------------------------- /* XXX Using _SGIAPI is the wrong thing, 194 but I don't know what the right thing is. */
39
1883
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 spawned thread is finished, but that's not the intended way, because i need that the opc variable change only when the user pushes a key, i think it has something to do with the pthread_attr_set(atribute) options, but i didn't get with the answer...
3
2395
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 *fd; fd = fopen("file.log","w"); fprintf(fd, "%s\n",<a character string>); This is done a by a thread in the server. Its a while(1) loop, so the
11
1945
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 verbatim) 1.
0
9899
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9750
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10672
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10740
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
7909
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
7076
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5937
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
4149
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3182
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.