[Date Prev][Date Next]
[Chronological]
[Thread]
[Top]
Re: per-thread init for overlays?
Aaron Richton wrote:
I'm linking an external library with my overlay that needs per-process
initialization, which I handle in my overlay_init function. I clean that
initialization up in the on_bi.bi_destroy function. (Feel free to yell at
me if that's the wrong place, but it seems to work.)
That sounds fine.
My question is for thread-specific initialization. The external library
claims thread safety, but in addition to the process init() call, there is
a per-thread thread_init()/thread_end() call. They recommend,
unsurprisingly, placing this near a pthread_create()/pthread_destroy() or
moral equivalent. Is there any appropriate place to do this in the
overlay?
Not really. Operations execute from a thread pool; thread
creation/destruction are hidden in the pool manager (and typically there
is no thread destruction at all). I can't really imagine what they need
to init and destroy, but if the issue is to make sure that each
operation gets a fresh context then you probably have to call
thread_init at the beginning of each operation the overlay intercepts,
and thread_end in the cleanup handler. If they really only care about
getting called once per created thread (and they don't care that each
thread is long-lived and gets re-used over and over) then you may have
to use the ldap_pvt_thread_pool_getkey/setkey functions. Set a key to
indicate that you've done the init, with a free handler that calls
thread_end. You'll have to test for the key at the beginning of each
operation, and set it if the key doesn't exist yet.
--
-- Howard Chu
Chief Architect, Symas Corp. http://www.symas.com
Director, Highland Sun http://highlandsun.com/hyc
OpenLDAP Core Team http://www.openldap.org/project/