Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm List-Subscribe: List-Archive: List-Post: List-Help: , Sender: cygwin-owner AT cygwin DOT com Delivered-To: mailing list cygwin AT cygwin DOT com Date: Thu, 24 Jan 2002 01:40:58 -0500 (EST) From: Haksun Li To: Subject: pthread_create or STL problem? Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Dear all, I am testing out the following piece of code using Cygwin. It works as expected (exits when failing to create a new thread) under Solaris and Linux. If the function test is called directly from main without invoking a new thread, the program works fine. If test is called as a new thread, then AND there are a lot of threads created, then Windows pops up a dialog box saying: The instruction at 0x00401141 referenced memory at 0x8d10c483. The memory could not be read. Note: no error (nor seg. fault) is caught inside the Cygwin shell. Moreover, if you change the number from 30000 to 500, there is no error. Also, if map is replaced by map, no error is generated even if threads are created. So, the problem only occurs when map type is used AND threads are created. I am thinking if there is a bug with Cygwin, so I am reporting my finding here. For those who know the answer, please help! Thank you very much! Code goes here (complied: g++ mapString.cpp lpthread) #include #include #include #include #include using namespace std; void *test(void *arg) { // map has no problem if called directly. // This creates memory errors if called by pthread_create. map testString; string one("1"); testString.insert(map::value_type(one, one)); //testString.insert(map::value_type(string("1"), string("1"))); //testString["1"] = "1"; //map has no problem regardless of being called from pthread_create or //being called directly. //map testInt; //testInt[1] = 1; pthread_exit(NULL); //return 0; } int main() { pthread_t tid[30000]; for (int i=1; i<=30000; i++) { cout << " i = " << i << endl; //test(0); if (pthread_create(&tid[i], 0, test, 0) != 0) { cerr << i << "-th thread creation error!" << endl; exit(-1); } } cout << "main: exiting..." << endl; return 0; } Best regards, Haksun -- Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple Bug reporting: http://cygwin.com/bugs.html Documentation: http://cygwin.com/docs.html FAQ: http://cygwin.com/faq/