-
Notifications
You must be signed in to change notification settings - Fork 47
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
InterruptibleTaskMutex with InterruptibleTaskCondition #118
Comments
The issue is a bit subtle here, as the code indeed looks totally fine from the outside. The problem comes from the fact that I'd love to get rid of the built-in monitor object in this case to at least get an error message in the |
Alternatively it would probably also be valid to use a normal |
what would happen if I use a normal mutex? In that code everything seems to work fine and even the background task on the same thread is still running while the mutex is locked |
As long as nothing blocks for an extended period of time during the lock, that would be fine, too. In that case it is an imperative to not
|
uh could you post some more full example code? This all seems a bit too error prone to deadlocks to me if I just try to apply your comments. I don't know what a |
The
string calculate()
{
import core.sync.mutex : Mutex;
auto mutex = new InterruptibleTaskMutex();
auto condition = new InterruptibleTaskCondition(mutex);
runTask({
sleep(10.seconds);
condition.notify();
});
{
auto l = scopedLock(mutex);
// ... can do something else here ...
condition.wait();
// ... can do something else here ...
}
return "done";
}
string calculate()
{
import core.sync.mutex : Mutex;
auto mutex = new Mutex();
auto condition = new InterruptibleTaskCondition(mutex);
runTask({
sleep(10.seconds);
condition.notify();
});
synchronized (mutex) {
{
auto l = yieldLock();
// ... can do something else here ...
}
condition.wait();
{
auto l = yieldLock();
// ... can do something else here ...
}
}
return "done";
} |
ah ok. Can a TaskMutex be used to lock in multiple threads? I think these questions I had here should be included in the documentation, it's rather sparse. Could the TaskCondition constructor maybe check what is being passed and raise a compile time issue for InterrutibleTaskMutex? |
Yes, Regarding |
Doesn't the TaskMutex become interruptible when being used with InterruptibleTaskCondition because the condition unlocks the mutex and can be interrupted in that time? Let's rename this issue to just adding some more documentation to the vibe.core.sync parts then. One more thing about usage with TaskMutex: there are overloads taking Lockable and Mutex which both match, I just cast to Lockable now and it works, is there any difference in using Mutex? |
Hm, I just got an idea. |
That would be the
Strange I never noticed this, I'll look into it. Both overloads should work the same, though. |
PR: #119 |
I'm not quite sure why this code wouldn't work? It just throws an unhelpful assert error:
Any reason for this design decision? Maybe an error message should be added or it should immediately catch and abort TaskMutex inside TaskCondition, this has caused multiple issues to me already and it seems just using a normal Mutex works fine without issues even though it's all one thread?
The text was updated successfully, but these errors were encountered: