diff options
author | Tomas Bzatek <tbzatek@redhat.com> | 2013-12-17 19:06:48 +0100 |
---|---|---|
committer | Tomas Bzatek <tbzatek@redhat.com> | 2013-12-18 11:42:45 +0100 |
commit | 3da04a083697de1d0784da37449e312c06e151f6 (patch) | |
tree | 38e73dc8bd633a86fd7e31a8cf96a6b328998096 /openlmi-mof-register | |
parent | 2bbdfe82be0660b0073f2e890115f5bce59bb270 (diff) | |
download | openlmi-providers-3da04a083697de1d0784da37449e312c06e151f6.tar.gz openlmi-providers-3da04a083697de1d0784da37449e312c06e151f6.tar.xz openlmi-providers-3da04a083697de1d0784da37449e312c06e151f6.zip |
indmanager: Rework thread cancellation again
The approach introduced in commit 381f4038a6a was on a good way however
turned out the pthread_cancel() actually queues a cancellation request
since we're using deferred cancellation mode and continues the code flow
until a function that is a cancellation point is called. We unlocked
the mutex before joining the thread which led to mutex acquisition by
the thread and then cancelling on a syscall, leaving the mutex locked
forever.
Having cancellation and join with mutex held was not a solution as it
would make the thread waiting for mutex leading to deadlock.
Instead, this patch introduces a private flag that will indicate the
thread should cancel itself. Two scenarios are possible:
- the thread is doing unlocked stuff, typically waiting for events
using syscalls that are cancellation points. In this case the
pthread_cancel() will take effect immediately, breaking the syscall
and quitting the thread. We're still in unlocked state.
- the thread is holding the lock, in that case the im_stop_ind() will
wait until that work is finished. It's better to leave the manage
thread finish its job, it's mostly CMPI stuff and breaking in the
middle would leak some memory. Once the main thread acquires the
mutex, it cancels the thread, sets a private flag and unlocks again.
While waiting for thread join is finished, the thread picks up the
lock again as it was waiting for it and as a first thing it will
check the private flag and quits gracefully, unlocking the mutex.
As a side effect, the pthread cancellation machinery has no chance
to kick in as there was no cancellation point on the way.
Diffstat (limited to 'openlmi-mof-register')
0 files changed, 0 insertions, 0 deletions