Long time did not write multi-threading, work for several years also did not how large-scale write too many threads, are formed in the structure of the business logic to write. Occasionally write their own down, all kinds of stepping pit ...
1.string is not thread-safe
One exception is std::string. In some implementations of the STL (including Ms VC6), a string! with reference counting is used This means that there may be two instances of std::string sharing the same piece of underlying data. This makes the first rule mentioned above be broken! string s1=string s2 = S1; In the implementation version of the reference count, these words mean allocating a piece of memory first to "ABCD", a reference count Both S1 and S2 will reference this memory, and the reference count will be 2. The reference count is intended to optimize the copy behavior when the strings is functions out. But this algorithm is not thread-safe ! If you pass S2 to another thread, it is likely that there are two threads attempting to modify the same piece of memory
Conclusion: Do not use string s1= "ABCD" by multiple threads; The value of this compile-time processing? I can't say I don't understand.
2.pthread_create parameter Passing pointer problem
http://blog.csdn.net/jfkidear/article/details/7918425
Conclusion: The function is used to pass parameters, do not pass pointers, or use, additional queues, thread pools
Linux C + + multithreading experience