Advertisement
Guest User

Untitled

a guest
Feb 23rd, 2017
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.77 KB | None | 0 0
  1. using namespace std;
  2. const static int kThreadSize = 48;
  3. map<string, string> gMap;
  4. string gStr = "";
  5. void * func(void * data)
  6. {
  7. while(true)
  8. {
  9. printf("%sn", gStr.c_str());
  10. pthread_mutex_t m;
  11. pthread_mutex_init(&m, NULL);
  12. pthread_mutex_lock(&m);
  13.  
  14. gStr = gStr + "a";//core in this line
  15. printf("%xn", &gStr);//print the address
  16.  
  17. pthread_mutex_unlock(&m);
  18. pthread_mutex_destroy(&m);
  19.  
  20. printf("%sn", gStr.c_str());
  21. }
  22. }
  23.  
  24. int main()
  25. {
  26. pthread_t threads[kThreadSize];
  27. for(int i = 0; i < kThreadSize; i ++)
  28. {
  29. pthread_create(&threads[i], NULL, &func, &gMap);
  30. }
  31. for(int i = 0; i < kThreadSize; i ++)
  32. {
  33. pthread_join(threads[i], NULL);
  34. }
  35. return 0;
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement