Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using namespace std;
- const static int kThreadSize = 48;
- map<string, string> gMap;
- string gStr = "";
- void * func(void * data)
- {
- while(true)
- {
- printf("%sn", gStr.c_str());
- pthread_mutex_t m;
- pthread_mutex_init(&m, NULL);
- pthread_mutex_lock(&m);
- gStr = gStr + "a";//core in this line
- printf("%xn", &gStr);//print the address
- pthread_mutex_unlock(&m);
- pthread_mutex_destroy(&m);
- printf("%sn", gStr.c_str());
- }
- }
- int main()
- {
- pthread_t threads[kThreadSize];
- for(int i = 0; i < kThreadSize; i ++)
- {
- pthread_create(&threads[i], NULL, &func, &gMap);
- }
- for(int i = 0; i < kThreadSize; i ++)
- {
- pthread_join(threads[i], NULL);
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement