Thread-safety and lazy-initialization of libraries
Sergey Protko via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Mon Jun 30 13:53:24 PDT 2014
For some research i decided to write small high-level binding for
libmpg123.
The question is how to write thread-safe lazy-initialization of
library.
libmpg123 has mpg123_init and mpg123_exit functions, which are
not thread-safe, so we should to call them only once per process.
Most of useful libraries also has such stuff. But manual
initialization is killing all beauty of high-level bindings.
Is there any proper way to do on-demand lazy-initialization of
used library, which will be also thread-safe? How do i need to
handle cases where some methods, which requires library to be
initialized, called from different threads at the same time?
Thanks for your answers.
More information about the Digitalmars-d-learn
mailing list