GithubHelp home page GithubHelp logo

problem to use Mutex. about grappa HOT 5 CLOSED

septicmk avatar septicmk commented on July 17, 2024
problem to use Mutex.

from grappa.

Comments (5)

nelsonje avatar nelsonje commented on July 17, 2024

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.

from grappa.

bholt avatar bholt commented on July 17, 2024

There's also the version of call that takes a Mutex of some sort and creates a heap-allocated continuation if it has to block: https://github.com/uwsampa/grappa/blob/master/system/Delegate.hpp#L159

I can't find any instances where it was used. I think I planned to use it in GlobalVector, but ended up manually using SuspendedDelegate: https://github.com/uwsampa/grappa/blob/master/system/GlobalVector.hpp#L146

We do have an alternate version of call that creates a task so it can be suspended, but as the documentation for that method indicates, this can be a problem because there's a chance of running out of workers, leading to deadlock (which happened frequently whenever I tried spawning dependent tasks inside of other tasks), so I encourage you to tread very lightly there.

from grappa.

septicmk avatar septicmk commented on July 17, 2024

@bholt could you show me a example how to use the version of call that takes a Mutex to try lock on remote mutex? I am confused about the way this functions works after reading the code.
Actually, I just want a function that lock( GlobalAddress<Mutex> m ) does, but I found that I can't use this function to lock on remote mutex since there is just a CHECK(false).
https://github.com/uwsampa/grappa/blob/master/system/Mutex.hpp#L106

from grappa.

bholt avatar bholt commented on July 17, 2024

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)

from grappa.

septicmk avatar septicmk commented on July 17, 2024

So, this function must return something non-void? Now I know how to deal with my remote mutex, Thank you!

from grappa.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.