Dictionary Locking

Discussions about design and architecture principles, including native JADE systems and JADE interoperating with other technologies
advaro
Posts: 19
Joined: Mon Oct 10, 2016 5:59 pm

Dictionary Locking

Postby advaro » Mon Jun 24, 2019 10:14 am

Hi,
I'm looking at sorting out a few lock issues I'm having with some of our bigger/busiest classes.

Just wanting to confirm, I thought Jade made a change many moons ago, that if the key of a dictionary isn't changed, even if it's set again, the dictionary wasn't locked. But that doesn't look to be the case.

I made a silly little method that sets the key again (to itself) and one that sets the reference that adds it to the dictionary again (also to itself).
begin
aDeviceToken := aDeviceToken;
app.doWindowEvents(5000);
end;

and setting the reference:
begin
rRootObject := rRootObject;
app.doWindowEvents(5000);
end;

Note - the delay is just so I have time to click refresh on my monitor to view the locks.

Running both these methods, even though it is setting the value to itself, creates exclusive locks on the dictionaries involved. Screenshot is attached.

So it appears for any key or reference I should be doing something like:
if aDeviceToken <> deviceToken then
aDeviceToken := deviceToken;
endif;

Is this correct? - as mentioned I thought we no longer had to do that basic check but it appears we do.

Many thanks
Stephen
Attachments
locks.png
locks.png (27.12 KiB) Viewed 4002 times

Kevin
Posts: 29
Joined: Wed Oct 14, 2009 9:03 am
Location: Christchurch

Re: Dictionary Locking

Postby Kevin » Mon Jun 24, 2019 2:30 pm

Hi Stephen,

You're correct, before setting a reference or key value, you should check whether it's actually changing to avoid locking & updating a collection.

I also use this same rule of thumb when updating a variable used as part of a condition to avoid collections being locked when the condition is being re-evaluated.

There may be a good reason why it works this way, but it would be nice if this could be optimized so we didn't have to write the code needed to check if a value is actually changing before setting. For which, you could submit this as an idea here: https://jedi.ideas.jadeworld.com/.

Cheers,
Kevin


Return to “Design and Architecture”

Who is online

Users browsing this forum: No registered users and 4 guests