Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

gcc and threads under Solaris

11 views
Skip to first unread message

Markus Breuer

unread,
Sep 12, 2001, 2:48:38 AM9/12/01
to
We habe problems with running our application in a
multithreaded environment. Under Solaris 2.7 / 2.8 serious
core dumps occures, when running on a real multiprocessor
machine. To find the error, I wrote a simple test
application, allocation std::string's for a map type. On
different machine are following results:

1.) Single processor: correct work, no core dump
2.) two processors: core dumpt after a short time-span, core
references to stl_alloc.h (seems, that some pointers are
wrong initialized, the pointer where the core occured
pointed to address 0x1)
3. ) two processors, but additionally used define _PTHREADS:
application runs out of control and allocates all available
memory, the app terminates when no more memory is available

--- application ---

#define _PTHREADS // used in 3.)
#define _REENTRANT
#include <pthread.h>
#include <thread.h>

#include <unistd.h>
#include <iostream>
#include <string>
#include <map>
#include <strstream>

//typedef basic_string<char,string_char_traits<char>,
malloc_alloc>

typedef std::string String;

const int max_thread_count = 8;
volatile int runningThreads = max_thread_count;
const char* my_default = "Hallo Welt!";

const int upper_limit = 2500;
const int lower_limit = 1000;


pthread_t tid[ max_thread_count ];

void* thread_main( void * )
{
unsigned int loop = 0;

cout << "Entering thread ..." << endl;

typedef map<unsigned int,std::String> Map;
typedef Map::value_type Value_Pair;
Map myMap;
do {
char buffer[32];

std::ostrstream oss( buffer, sizeof(buffer) );
oss << loop << '\0';

std::String& str = myMap[ loop ];
str.append( my_default );
loop++;

if ( myMap.size() > upper_limit )
{
cout << "cleaning up ..." << endl;
while( myMap.size() > lower_limit )
{
Map::iterator it = myMap.begin();
myMap.erase( it );
}
sleep( 5 );
}

} while ( loop );
cout << "Leaving thread ..." << endl;
runningThreads--;
}


int main()
{
int ctr;

cout << "Startup ..." << endl;

for( ctr=0; ctr < max_thread_count; ctr++ )
{
pthread_t pt = pthread_create( &tid[ctr], NULL,
thread_main, 0 );
cout << "thread " << ctr+1 << " started ..." << endl;
}
while( runningThreads )
sleep ( 1);

cout << "Shutdown ..." << endl;


return 0;
}
--- application ---

Im using g++ 2.95.3 on Solaris 2.7 / 2.8.
Is anyone able to tell me, why the problem occurs?

regards,
Markus

Kristijan Caprdja

unread,
Oct 15, 2001, 4:11:51 AM10/15/01
to

> Im using g++ 2.95.3 on Solaris 2.7 / 2.8.
> Is anyone able to tell me, why the problem occurs?

We are fighting with a similar problem, there seems to be a problem with
the standard allocator in g++ STL. Try compiling with
#define __USE_MALLOC. This will use different allocator. Tell us whether it
helped.
The problem seems to occur only on Solaris x86. Sparc solaris seems to be
ok. We are not sure if this is a solaris or g++ problem.


--
Kristijan

Paul Pluzhnikov

unread,
Oct 16, 2001, 2:08:10 AM10/16/01
to
"Kristijan Caprdja" <cap...@hand-gmbh.de> wrote in message
news:9qe5om$nu64v$1...@ID-63733.news.dfncis.de...

I did not see the original post, only this reply.
Presumably, OP observed crashes in the gcc's STL allocator.

This problem is *not* in the gcc allocator, and it is not
a solaris problem. It is *certainly* not x86-specific, as
I have observed it on a SPARC.

Rather, it is a (lack of) documentation problem:

You should simply compile all MT code with -D_PTHREADS,
if you are using g++. Without this, stl_allocator.h becomes
totally (thread) unsafe.

Look in .../include/g++-3/stl_config.h and stl_allcator.h
for further info.

Kristijan Caprdja

unread,
Oct 17, 2001, 8:56:50 AM10/17/01
to

> I did not see the original post, only this reply.

> You should simply compile all MT code with -D_PTHREADS,

Program in the original post was compiled using _PTHREADS. I will repeat
the original post here. Also I have problems with other programs compiled
using -D_PTHREADS, and -D_REENTRANT. If somebody is interested I can place
my example program here (which is much simpler than the first example).

Original post:

>--- application ---

>typedef std::string String;


>pthread_t tid[ max_thread_count ];


>int main()
>{
> int ctr;

> cout << "Startup ..." << endl;

> cout << "Shutdown ..." << endl;

>Im using g++ 2.95.3 on Solaris 2.7 / 2.8.


>Is anyone able to tell me, why the problem occurs?

>regards,
> Markus


--
Kristijan

0 new messages