File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
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


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Languages » C / C++
Bookmark "Delete an object in concurrent situation" Watch "Delete an object in concurrent situation" New topic
Author

Delete an object in concurrent situation

David Freeman
Greenhorn

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: 41
    
    2

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.

en.cppreference.com/w/cpp/language/storage_duration

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
 
jQuery in Action, 2nd edition
 
subject: Delete an object in concurrent situation
 
Similar Threads
java.lang.ArrayIndexOutOfBoundsException while marshalling with JAXB
FileChannel and thread safety
Failed b/c of locking. Any ideas?
What can Scala do for concurrent programming that Java can't?
NIO read/write review