Delete an object in multi-thread situation

I have to delete an object at a time that I don't know it's held by another thread(s) or not.
For example

1
2
3
4
5
6
7
static void foo(CLASS* ref){
pthread_mutex_lock(&l);//[POINT-A]
    //using ref
    //do something thread safe
pthread_mutex_unlock(&l);
delete ref;// how can I find out there is no any thread held at [POINT-A]
}


Thanks in advance
Sounds like a job for std::shared_ptr.
Sounds like a job for std::shared_ptr.

Would you please give an example? or a link? many thanks dear.
Topic archived. No new replies allowed.