This is the mail archive of the libstdc++@gcc.gnu.org mailing list for the libstdc++ project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

RE: File Stream Open Problem with g++ 3.3.3 and libstdc++.so.5


Hi Jonathan & Paolo

As per your suggesstion, I collect the data for
ulimit -n and errno, it is given below. The most
strange thing is if I compile the same code using
g++ 2.95.3 and libstdc++.so.2.10.0 and run the executable
under the same environment, then there is NO PROBLEM.

This problem occurs only when I compile my code with
g++ 3.3.3 and libstdc++.so.5.

Please take a look below into the output and my code
and kindly let me know your opinion.

With Best Regards

Subrata Basak

OUTPUT :
========
$ echo $SHELL
/usr/bin/sh
$ 
$ ulimit -n
50000
$ 
$ ./a.out
i : 253
errno : 24
Assertion failed: in[i], file main.cpp, line 28
Abort - core dumped
$
========

MY CODE :
=========
#include <sys/errno.h>
#include <assert.h>
#include <fstream>
#include <iostream>
#include <string>

extern int errno;

const int MAX_STREAM = 1000;

using namespace std;

int main(int argc, char* argv[])
{
        ofstream in[MAX_STREAM];
        string file("boo");

        for ( int i=0; i != MAX_STREAM; i++ )
        {
                in[i].open(file.c_str(), ios::out);

                if ( errno > 0 ) {

                    cout << "i : " << i << endl;
                    cout << "errno : " << errno << endl;

                } // end of "if ( errno > 0 ) {"

                assert(in[i]);
        }
        return 0;
}
=========



-----Original Message-----
From: Jonathan Wakely [mailto:cow@compsoc.man.ac.uk]
Sent: Monday, March 29, 2004 7:12 PM
To: Subrata Basak
Cc: 'gcc-libstdc++'; sin-ming@mediaring.com; halim@mediaring.com
Subject: Re: File Stream Open Problem with g++ 3.3.3 and libstdc++.so.5


On Mon, Mar 29, 2004 at 04:50:16PM +0800, Subrata Basak wrote:

> 
> Hi
> 
> I am facing one problem when I complie and run my code
> with the following compiler and standard c++ library :
> 
> Compiler Used : g++ 3.3.3
> Standard Library Used : libstdc++.so.5
> 
> Problem : I am supposed to create 1000 file stream, 
> but when I run my program, it creates only 254 file stream, 
> after that assertion occurs!!!!

This sounds like an artificial limit:

254 + stdin + stdout + stderr = 257

i.e. fails when number of open file descriptors > 256

Were you in the same environment each time you ran the program?
Have you checked the value of "ulimit -n" ?

As Paolo suggests, something's possibly broken with your GCC 3.3.3
installation, try gcc-help@gcc.gnu.org and provide more details of
your environment and what goes wrong (e.g. the value of errno)

jon


>                
> My Code :
> ============================
> #include <assert.h>
> #include <string>
> #include <fstream>
> 
> const int MAX_STREAM = 1000;
> 
> using namespace std;
> 
> int main(int argc, char* argv[])
> {
>         ifstream in[MAX_STREAM];
>         string file("boo");
> 
>         for ( int i=0; i != MAX_STREAM; i++ )
>         {
>                 in[i].open(file.c_str());
>                 cout << "i : " << i << endl;
>                 assert(in[i]);
>         }
>         return 0;
> }
> ============================
> 
> But, if I use the exactly same program with the following
> compiler, it is running without any problem and 1000 file
> streams are created smoothly without any assertion.
> 
> Compiler Used : g++ 2.95.3
> 
> Standard Library Used : libstdc++.so.2.10.0
> 
> Anybody can help me to overcome this problem with
> g++ 3.3.3 compiler and libstdc++.so.5 library.
> 
> With Very Best Regards
> 
> Subrata Basak
> MediaRing Ltd., Singapore
> 
> 

-- 
VOTE, v.  The instrument and symbol of a free man's power to make
a fool of himself and a wreck of his country.
	- Ambrose Bierce, 'The Devil's Dictionary'


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]