I have 3 classes: Meeting, Project and Agenda.
- A Project contains all sort of information + a list of meetings.
- The Agenda contains a list of upcoming Meetings.
- A Meeting contains some data + a list of Projects that were discussed there.
The Agenda checks for upcoming meetings. When it finds one, it calls its Meeting::alarm() method, which in turn displays data it gets from the list of projects this meeting refers to.
Meetings can be referenced in a project without being scheduled in the Agenda, but it doesn't really make sense to have a reference to a meeting in the agenda if it is not contained in a project.
Because the Agenda can be parsed in a thread while the main thread deletes a project, I made both Agenda and Project use shared pointers on Meetings, so that the parsing thread doesn't find a dangling pointer.
In the destructor of Project, I ask Agenda to check the meetings related to this project to clean up those who don't have any other related project.
Here is my problem:
What kind of data structure should the Meeting::parentProjects member be?
If a Meeting gets called by the Agenda while its Project is being deleted, and parentProjects is a simple raw pointers container, I might have a dangling here. But I can't use a shared_ptr to Project either, since that would make a cyclic dependency... I feel like it is unnecessarily complicated.
How could I refactor this? Note: I have to keep the 2 threads though.