jQuery in Action, 3rd edition
The moose likes C / C++ and the fly likes Delete an object in concurrent situation Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Languages » C / C++
Bookmark "Delete an object in concurrent situation" Watch "Delete an object in concurrent situation" New topic

Delete an object in concurrent situation

David Freeman

Joined: Jun 27, 2013
Posts: 2
Hi folks
I just stuck at a very simple problem in concurrent application in cpp.
so the problem is, in a parallel application, I want to delete an object at a time, but I don't know when should I delete it, because this is possible just after deleting the object the blocked thread wants to use it. i other word I want to know how many threads are holding the reference at a same time, and the hard thing is deleting the object is done by a thread-safe function.

for example

A friend told me to use std::shared_ptr, but if I be honest, I really cannot figure out how would I use it in this situation.
thanks in advanced.
Luke Leber
Ranch Hand

Joined: Sep 20, 2013
Posts: 69

Are you sure sharing access to the object is the best course of action?

Personally, I would use thread-local storage and forget about the problem entirely if the cost of making a few copies isn't that outrageous.


The C++ standard guarantees that a shared_ptr implementation is thread-safe, however makes absolutely no guarantees about the thread-safety of objects accessed through them.

Remember, C++ is not C

I agree. Here's the link: http://aspose.com/file-tools
subject: Delete an object in concurrent situation
It's not a secret anymore!