Greg Hudson <[EMAIL PROTECTED]> writes: > My idea is to provide an APR interface like: > > apr_status_t apr_thread_mutex_get_named(apr_thread_mutex_t **mutex, > const char *name); > > which would create or fetch from a global hash table a mutex by name. > APR can use a mutex (presumably one created by apr_initialize) to > serialize access to the hash table. > > Do people think this is a reasonable feature, or have other ideas for > how to solve this sort of problem?
The obvious answer on a POSIX like system is to allow static initialisation of mutexes, this would probably have to be a separate type and not an apr_thread_mutex_t. I don't know whether such a thing is possible on Windows, it's absence from APR suggests not. The other answer on a POSIX system is a thread-once function. APR provides these but they suffer the same problem as APR's mutexes--they don't support static initialisation. A variant to your named mutex idea would be to use a similar method to provide a thread-once interface that didn't require dynamic initialisation. This would still require a global hash table, to hold function addresses in this case, but might require fewer mutexes. Of course it's likely that the thread-once functions would be used to create mutexes so this may not be much of a saving. -- Philip Martin