Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Why are STLs not thread-safe? 1

Status
Not open for further replies.

maluk

Programmer
Oct 12, 2002
79
0
0
SG
I have read in most articles that STL is not thread-safe or should not be used in multi-threading? Why? What are other alternatives or how should one make a thread-safe STL?

Rome did not create a great empire by having meetings, they did it by
killing all those who opposed them.

- janvier -
 
There are safe versions about but they operate slower. The basic rationale was that locking is expensive and if you dont need it why pay for it. Its not hard to write a class with a container member and a critical section to sync access to the container. In general where stl containers must be shared across threads I find a single writer/multiple reader lock works really well similar to the one shown in Richters book.
 
If you google 'stl' 'interview', you will get the interview from the originator. He explained the thread-safe issue and why STL is not OO.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top