Hi, Don:
  Thank you for answering the question. 
  Let me tell you more about the problem. I construct the map with "insert"
before 
creating any threads, after that, all the threads just "find" in the map,
starting 
from thread number 21, map.find() starts to return end() which means it
doesn't find 
some object in the map, however it should because in thread # below 21, it
really 
success.  Puting lock with "insert" make little sense, because when "insert"
is 
happening, there is only one thread running (main thread). Adding lock with
"find" 
seems doesn't make much sense either, because "find" looks like a read
operation. 
By the way, I did an experiement by adding lock with "find",  still have the
same 
problem. 
  Don't have a clue.
  
  Liu


------
Hi Liu,

No, it is not thread safe. No implementation that I can think of is. The
assumption is that concurrency issues will be accounted for at a higher
level. A brute force solution would be to surround each insert/erase
with a mutex. A more elegant solution would be to use rw locks to allow
multiple reads, but only one write. If you've got 20+ threads, the rw
locks might be worth the aditional effort, but then again, it would
really depend on you access patterns. Do you have Unix Network
Programming Vol 1, by W. Richard Stevens? It's a great reference for
exactly what you seem to be doing.

Hope this helps,

Don

"Liu, Guangsheng" wrote:
> 
> Hi,
>   I have a problem with <map>. When I create more than 20 thread,
map.find()
> starts to return end() which it should not.
> I am wondering the whole STL distributed by Red Hat multi_thread safe. If
it
> is not, what is the alternative?
>   The following is info about OS and compiler (I have not installed
anything
> particular).
>     Red Hat Linux 6.2
>     kernel version: 2.2.14
>     gcc 2.95.2
> 
>   Thanks
> 
> 
> _______________________________________________
> Redhat-devel-list mailing list
> [EMAIL PROTECTED]
> https://listman.redhat.com/mailman/listinfo/redhat-devel-list



_______________________________________________
Redhat-devel-list mailing list
[EMAIL PROTECTED]
https://listman.redhat.com/mailman/listinfo/redhat-devel-list



_______________________________________________
Redhat-devel-list mailing list
[EMAIL PROTECTED]
https://listman.redhat.com/mailman/listinfo/redhat-devel-list

Reply via email to