Is CMap's PLookup thread safe ??
-
Hi, I am using CMap. While adding and deleting elements I am using Locks because there are multiple threads :doh: Do I need to put lock before using pLookup function? Sometimes it crashes while looking up for an element. My lookup statement is like below :
if(cmap\_buffer.PLookup(element.orderId) != NULL) st\_order = cmap\_buffer\[element.orderId\];
Thanks, Rahul Kulshreshtha
-
Hi, I am using CMap. While adding and deleting elements I am using Locks because there are multiple threads :doh: Do I need to put lock before using pLookup function? Sometimes it crashes while looking up for an element. My lookup statement is like below :
if(cmap\_buffer.PLookup(element.orderId) != NULL) st\_order = cmap\_buffer\[element.orderId\];
Thanks, Rahul Kulshreshtha
It is not thread safe. You will have to manually add the locking before accessing its data. Imagine what would happen if a node is removed while PLookup is using it. The easies way of creating a thread safe container is to embed an existing container in a new class with the same interface, or a subset thereof if sufficient, forwarding all calls to the aggregated container and adding all the locking in between.
-
It is not thread safe. You will have to manually add the locking before accessing its data. Imagine what would happen if a node is removed while PLookup is using it. The easies way of creating a thread safe container is to embed an existing container in a new class with the same interface, or a subset thereof if sufficient, forwarding all calls to the aggregated container and adding all the locking in between.
Thanks Niklas, Using a thread-safe container will be a good solution. I wish Microsoft should provide some in-built thread-safe containers. As currently there is no inbuilt thread-safe way so I will go for creating my own. But I will not be able to use it in this project because it is 90% completed and implementing a new container and replacing it over existing map will take a big code-patching. Thanks, I will take care this next time.