fungos / cr

cr.h: A Simple C Hot Reload Header-only Library
https://fungos.github.io/cr-simple-c-hot-reload/
MIT License
1.56k stars 104 forks source link

Multi-process support #23

Closed rokups closed 5 years ago

rokups commented 5 years ago

My application spawns several worker sub-processes of itself. These instances need plugins loaded as well. Situation here gets hairy. Each subprocess insists on renaming original plugin file and each subprocess is counting from 0. Collisions happen between subprocesses and between subprocess and main process.

Would it be possible to somehow handle this situation?

Few things come to my mind:

Include host process id in renamed plugin name. This is probably not a good idea due to name becoming too long and interfering with patching pdb path on windows.

Create a directory with host process id in it's name, put renamed plugins there. This is probably better, common directory prefix could allow easy cleanup of these directories.

But i do not particularly like either suggestion. Maybe someone has a better idea?

rokups commented 5 years ago

Update: I experimented a bit and concluded that including process id in renamed plugin file name is a viable approach. Test implementation here. For MSVC i also trimmed down PDB path leaving only file name. Debugging still works and this should give a room to breathe for PDB file names. The only situation where it would still break is if someone decided to compile their software in a directory with very short path (like C:\).

fungos commented 5 years ago

The most clean would probably to ask for a workspace folder where to put temporary data, this would be per context. But I think the process id is a acceptable and transparent solution anyway.