Add lifecycle callback functions for worker threads. #245
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Added lifecycle callback functions for worker-thread start and stop. The idea behind this PR is the following:
MonstorDB uses user-space update-copy-update (rcu) libraries to manage frequently-read-but-rarely-updated data structures. The library requires each participating thread to call a "register" function before its first use of the library and a "unregister" function before the termination of the thread's main function. Currently, MonstorDB uses a thread-local boolean flag to track the thread's first use, and relies on another thread-local variable's destructor to call the "unregister" function. It seems to work at the moment, but theoretically it depends on the order of thread-local variable's destruction order and may break in future in a very subtle way. I'm planning to fix that by explicitly calling "register" and "unregister" functions inside each thread's main function (for threads using the rcu library only). Currently, the "pre_commit" callback functions may use the rcu library. Therefore, I added the two hooks on the worker thread's main function.