I've shared read-only data across threads many times a cheap and easy
caching mechanims, but as I'm sure you've found in your research, the
"copy-on-write" methodology employed by mod_perl prevents you from doing
that for mutable data and I'm not aware of a way around that without
fundamental changes to mod_perl itself.
There are some very good reasons that mod_perl is architected that way.
You may very well have a specific use case that makes sharing mutable
data in memory for a threaded application desirable, but I know that
oftentimes when I've tried to find ways to workaround a fundamental
architectural element in a toolset, the best solution for me has
ultimately been to rethink my approach rather than to wrestle the
toolset into submission.
In short, and although this isn't what you asked and I know next to
nothing about your project, constraints or requirements... it sounds
like you might want to consider a cache server
(Redis/Varnish/Elasticache/etc...) and then solve the problem and
proactively notify subscribed threads of changes if you need to.
On 8/24/2021 7:50 PM, David Booth wrote:
I am using Apache/2.4.41 (Ubuntu), with mod_perl. Apache uses
multiple threads, and I want to share read/WRITE data between threads.
(I.e., I want to be able to modify some shared data in one thread,
such that other threads can see those changes.) In "Practical
mod_perl" Stas Bekman describes how to share read-only data between
threads, but says nothing about how to share WRITABLE data between
threads.
Any clues about how this can be done? I've searched high and low and
found nothing. I will also want to know what mechanisms are available
to coordinate access to that shared data, such as locks or semaphores.
I also posted this message to StackOverflow, but got no response so far:
https://stackoverflow.com/questions/68901260/how-to-share-read-write-data-in-mod-perl-apache2
Any help would be appreciated!
Thanks,
David Booth