4/11/2007

04-11-07 - 2

Critical Sections don't work across processes (mainly just because they do local allocs, so they have internal handles and pointers which are process-specific). (I guess there's also some differences between windows process-switch and thread-switch logic which would call critical sections to be unsafe across processes even if their memory was global).

Windows doesn't have any drop-in cross-process data locking thing. Fortunately some MS dude wrote a cool bit of free code : Metered Sections

There is one bad thing about the Metered Section code as is, which is that the Open and Close use malloc and free which is not safe to call inside DllMain. My preferred fix to that is to expose the in-place Init() and Delete() analogous to Critical Sections, so that you can just have a Metered Section structure in a static variable and initialize it in place with no allocs. If you wanted them to be safe & dynamic you'd have to use TlsAlloc or something.

No comments:

old rants