This is the mail archive of the cygwin@cygwin.com mailing list for the Cygwin 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]

pthread_create or STL problem?


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/


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