Skip to main content
1-Visitor
Mar 11, 2016 5:32 AM UTC
Question

Concurrency

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?

    3 replies

    1-Visitor
    Mar 11, 2016 7:58 AM UTC

    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.

    Translate
    cscholtz1-VisitorAuthor
    1-Visitor
    Mar 11, 2016 8:26 AM UTC

    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?

    Translate
    1-Visitor
    Mar 11, 2016 8:44 AM UTC

    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.

    Translate