Object delete itself from container

后端 未结 4 976
耶瑟儿~
耶瑟儿~ 2021-01-16 15:59

So I have a container(any kind, probably std::map or std::vector) which contains objects of a class with some network thing running in a thread that checks if it is still co

4条回答
  •  春和景丽
    2021-01-16 16:33

    I would have am unload queue.

    When a thread notices that the connection is down it registers the object (and continer) with the unload queue tides everything up as much as possible then the thred terminates.

    A separate thread is then inside the unload queue. Its sole purpose is to monitor the queue. When it sees a new object on the queue, remove it from the container and then destroy it (syncing with the objects thread as required).

提交回复
热议问题