Author | Message | Time |
---|---|---|
shadypalm88 | Note: I'm currently developing under Windows, but any general suggestions would be appreciated. I'm wondering if there's some type of built-in synchronization facility that meets these requirements. I have a bunch of threads, and each thread has a data structure assigned to it. These structures, as they sometimes need to be accessed by other threads, are stored in a global, dynamically-allocated array. Currently I'm using critical sections to control access. But that's too restrictive, IMO. Once the structure is created and its values initialized, it no longer needs to be written to, only read from (except one field that doesn't need to be accessed from outside the owning thread). So is there any (relatively straightforward) way to: - Allow read operations to go through "simultaneously", while still signaling some sort of controller that the read operation(s) are in progress, but - When the array needs to be resized, the resizing function can signal that, blocking out all new read operations and waiting for all pending operations to complete, and then reallocating the memory for the array, unlocking it, and allowing reads to continue. Basically a tri-state mutex: unlocked, read-only, and fully locked. | March 8, 2005, 2:14 AM |
Arta | Windows does support this natively, but the API are undocumented. I'm not sure where to look for more info, Skywing could point you the right way though. Multiple Reader Single Writer synchronisation is definitely what you're after, though, and that's what these API are designed for. | March 8, 2005, 2:22 AM |
Kp | As an extension to Arta's comments, you can build your own SWMR primitive if you can't or don't want to dig through the API documentation. It's pretty simple, and comes up in most OS classes. | March 8, 2005, 3:26 PM |