delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2002/01/24/01:42:17

Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm
List-Subscribe: <mailto:cygwin-subscribe AT cygwin DOT com>
List-Archive: <http://sources.redhat.com/ml/cygwin/>
List-Post: <mailto:cygwin AT cygwin DOT com>
List-Help: <mailto:cygwin-help AT cygwin DOT com>, <http://sources.redhat.com/ml/#faqs>
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 <haksunli AT engin DOT umich DOT edu>
To: <cygwin AT cygwin DOT com>
Subject: pthread_create or STL problem?
Message-ID: <Pine.SOL.4.33.0201240139430.7774-100000@blue.engin.umich.edu>
MIME-Version: 1.0

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<string,string> is replaced by map<int, int>, no error is
generated even if threads are created.



So, the problem only occurs when map<string, string> 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 <stdio.h>

#include <stdlib.h>

#include <pthread.h>

#include <map>

#include <string>



using namespace std;





void *test(void *arg) {



  // map<string,string> has no problem if called directly.

  // This creates memory errors if called by pthread_create.

  map<string,string> testString;

  string one("1");

  testString.insert(map<string,string>::value_type(one, one));

  //testString.insert(map<string,string>::value_type(string("1"),
string("1")));

  //testString["1"] = "1";





  //map<int, int> has no problem regardless of being called from
pthread_create or

  //being called directly.

  //map<int, int> 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/

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019