on 06-05-2019 2:29 PM
Hello guys,
do anyone of you know a thread safe way to increment variables (In this case global variables in IdM 7.2.)
in global/public javascripts.
If I'm using uGet...Var and uSet...Var I expierience possible race conditions, as I have no semaphore embracing both calls.
Thanks in reward,
Ansgar
Hi Matt,
thanks for your ideas. I decided to use a database sequence instead. This is not that transparent to the developers but it is easy and failsafe.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Matt,
I'm using a global counter in a global javascript as follows
// fetch the global var<br>var numStr = uGetGlobalVar("A_GLOBAL_VAR");
//increment the value (only symbolic code as we need some string conversion)
numStr++;
do something with the number
// set the global var
uSetGlobalVar("A_GLOBAL_VAR", numStr );
This script is called from different places, so that it happens that the script is running 2 times at the same time.
If the second caller fetches A_GLOBAL_VAR before the first caller has called A_GLOBAL_VAR both callers are using the same value and the global var is only incremented once.
Hope that makes it more clear.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Yes, I suppose it does. That could be a tough one to crack.but I could think of a couple of approaches, all theoretical, but it might give you something to work with.
1. After each task which updates the variable put a pause/sleep in to allow other processes to stop. This probably won't scale.
2. Can you use an attribute or create some sort of flag that can be used by the process to see if it is "checked out" and wait for it to clear before going on? The value of the flag will probably need to be a date/timestamp.
Not really sure how you would set these up, unfortunately I do not have the bandwidth to prototype something like this at the moment, but maybe it will spark an idea for you or someone else in the community.
User | Count |
---|---|
90 | |
10 | |
10 | |
10 | |
7 | |
7 | |
6 | |
5 | |
4 | |
3 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.