Hi,
We have an existing 'AutoNumbering' plugin running on create entity X that needs to increment a counter that is stored in entity Y and add the content to a field in entity X
The plugin is using a critical section (2 to 7 below) in order to avoid race conditions.
1 enter plugin for entity x
2 enter critical section (Mutex)
3 retrieve the counter from y
4 increment counter
5 update counter in y
6 set entity x's field = counter
7 Exit critical section (Mutex)
8 leave the plugin
The scenario above does not work correctly when concurrent clients call Create x. We sometimes get duplicate values in entity X
We kind of figured out that the update (5) does not execute until later when the threads leaves the plugin (8), but this is too late because a context switch already occurred and the next client is reusing the value counter that has not been saved yet.
Is there a way to call (3) and (5) using the SDK with a different transaction?
Thanks
Christian