Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add lifecycle callback functions for worker threads. #245

Merged
merged 2 commits into from
Aug 2, 2021

Conversation

yong-li
Copy link
Contributor

@yong-li yong-li commented Aug 2, 2021

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.

#ifdef __linux__
pthread_setname_np(pthread_self(), thread_name.c_str());
#elif __APPLE__
pthread_setname_np(thread_name.c_str());
#endif

if (my_opt_.worker_start_) {
my_opt_.worker_start_(worker_id);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure worker_id is what you intended (it is different from thread ID). Let me merge it for now.

@greensky00 greensky00 merged commit 7aa8eb1 into eBay:master Aug 2, 2021
@yong-li yong-li deleted the worker_cb branch August 2, 2021 22:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants