-
Notifications
You must be signed in to change notification settings - Fork 51
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
problem to use Mutex. #289
Comments
Delegate operations can't contain blocking code---the lock() call may block. You can wrap it in a spawn() call to spawn a new task, which will be able to block. |
There's also the version of I can't find any instances where it was used. I think I planned to use it in We do have an alternate version of |
@bholt could you show me a example how to use the version of |
It's definitely pretty wonky. I meant to wrap it in some nicer functions but never got around to it. It was intended to be as general-purpose as possible, so it takes 2 lambdas: one lambda is like a delegate, but its only purpose is to return a pointer to the Mutex that you want to lock/wait on. Then, when the mutex is unlocked, the second lambda parameter will get invoked, which should probably lock the mutex. But due to me being lazy a long time ago, you also have to return something non-void. So, long story short, I think this should work to do a remote lock as a blocking delegate: GlobalAddress<Mutex> mptr = /* get global address somehow */;
bool result = delegate::call(mptr.core(),
// runs on remote node; computes local pointer to mutex
// (in this case just getting the pointer component of the
// GlobalAddress, but could be whatever you want)
[mptr]{ return mptr.pointer(); },
// runs once the mutex is unlocked; should probably lock it,
// but then you can also do whatever other work you want,
// such as returning a value from this remote node.
// in this case I just return "true" (have to return something)
[](Mutex* m){
lock(m);
return true;
}); (caveat: I haven't tested this beyond making sure it compiles) |
So, this function must return something non-void? Now I know how to deal with my remote mutex, Thank you! |
I intend to use the following code to figure out how to lock a mutex, but...
OK, so far so good, but I got the following errors when I use
mpiexec -n 4 ./test
to run this case.Did I do something wrong?
The text was updated successfully, but these errors were encountered: