Using locks from other objects
oodes
Posts: 131
Hello,
I'm wondering is it possible to use a lock that i have declared in my top object folder but use from another lower object folder. I have my main cog executing and writes to a logfile events on an sd card and i have wrote another object that emails me the logfile when requested. But i need to put a lock on the logfile so 2 cogs dont access it at the same time. Works fine when I'm using other locks within the same object folder but when i try to use the same lock from different objects its causing problems.
Thanks Des
I'm wondering is it possible to use a lock that i have declared in my top object folder but use from another lower object folder. I have my main cog executing and writes to a logfile events on an sd card and i have wrote another object that emails me the logfile when requested. But i need to put a lock on the logfile so 2 cogs dont access it at the same time. Works fine when I'm using other locks within the same object folder but when i try to use the same lock from different objects its causing problems.
Thanks Des
Comments
Works great.
Alex
so just calling the methods from outside will be protected. So for instance an SPI library would
use a lock to protect access to the bus it is handling, and you would only need to call methods
on the instance to get the lock handling automatically.
This of course just moves the problem to that of gaining a handle for the right instance in two places,
There is a subtle issue of recursive access to locks - when code in the same cog is calling methods in
several libraries and each instance is using the same lock then there is a risk of trying to claim a lock
recursively (not supported by Prop locks). The way to avoid this is to only use a lock for one purpuse in
one library, share the reference to the instance, not the lock, and write the library to not recursively claim
the lock.
Yes I was unsure if the resource was protected when I called from an outside object. I had a lock on the resource within the main object folder but i wasn't sure if this remained protected when i called from another object the same resource without using the lock in place.
Thanks
Des