Skip to main content
1-Visitor
March 11, 2016
Question

Concurrency

  • March 11, 2016
  • 1 reply
  • 2079 views

Can I use a thing property as a mutex lock? Is there any guarantee that when events arrive at the same time, they wont all read the lock to be open at the same time and all try to lock it in the next operation?

    1 reply

    1-Visitor
    March 11, 2016

    Hi Christiaan,

    To get a lock you need to update a persistent property, if you update a persistent no one will update that Thing until the service you are it's done.

    Carles.

    cscholtz1-VisitorAuthor
    1-Visitor
    March 11, 2016

    Thanks Carles.

    So does that mean other services writing to the property at the same time will block, or will they simply fail to update it and continue execution? Can they still read it concurrently? If it blocks for the duration of the service, this implies I should put the code updating the property in its own service to minimize waiting time, right?

    1-Visitor
    March 11, 2016

    No Property Blocking, whole Thing Blocking, any service trying to access to that Thing will be blocked - block not continue execution -.

    Well I don't know the insights 100%, what you say it depends on how trasactions works and I still don't have all the clues What I mean, it's still if you put the updating property code inside a service, the transaction will be one the one on the wrapping service, then you will get blocking for the wall wrapping service not just the one that writes the property ( I've already have a Lock() generic service on my "Master" Generic ThingShape to be able to lock when I want --> I usually don't do it )

    Carles.