Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sychronization in behavior #1014

Open
ssardina opened this issue Jun 20, 2020 · 1 comment
Open

Sychronization in behavior #1014

ssardina opened this issue Jun 20, 2020 · 1 comment

Comments

@ssardina
Copy link
Contributor

ssardina commented Jun 20, 2020

Description of your issue:

Suppose this code:

behavior B_Coordinator {
	var teamRoles = new HashMap<String, Integer>()

	on Initialize {
		teamRoles = occurrence.parameters.get(0) as HashMap<String, Integer>
...

I get the "The field teamRoles should be synchronized for avoiding value inconsistency due to parallel execution"

My understanding is that each B_Coordinator behaviour is different for each agent when attaching it to an agent, so they do not share the same teamRoles and there could be no problems due to || executions. And of course a behavior can only be initialized once right?

So shouldn't be the case that the Initialize of behaviors shold never rise these warnings as they are by definition executed once? Maybe I am not understanding soemthing

System configuration:
-- SARL version: 0.10.0
-- SARL compiler: 0.10.0

    • Eclipse compiler without Maven
    • Eclipse compiler with Maven
    • Maven compiler on the command line
    • sarlc compiler
      -- Java JDK version (with the manufacturer name): OpenJDK 11
      -- Operating System:
    • Linux 64bits
    • Windows 64bits
    • MacOS 64bits
@gallandarakhneorg
Copy link
Member

gallandarakhneorg commented Jun 20, 2020

You could declare multiple times a on Initialize into a single behavior (as in an Agent). Please note that the documentation is not enough clear at this moment, and it should be updated to explain that multiple on Initialize could be declared.
All of the on Initialize are executed in parallel. In this case the parallel access to your field is possible.

I understand that from your code, we are almost sure that there is no possible parallel execution because there is only one on Initialize in the current behavior, and there is no super behavior that is extended (and that may implement its own on Initialize).

But, because your behavior is not declared as final (i.e., it is still overridable), on Initialize could be declared into a sub-type of your behavior. In this case, you may encounter parallel access issues.

Unfortunatelly, if you add the final modifier to your behavior, it will not remove the warning for now. Indeed, the SARL validator does not do a so detailled analysis of the code as the one above, until now. It may be a nice enhancement for the coming version.

Keep in your mind that the synchronization issues that are generated by the SARL compiler are warnings (should be considered, could be ignored). We plan to remove them in one of the coming versions (see Issue #208).

I keep this issue open in order to:

  1. Update the documentation regarding the explanation on the multiple declaration of on Initialize.
  2. Determine, according to advancements on Issue Manage the mutual exclusion of agent attributes used in different "on" statements or in different behaviors #208, if we need to update the SARL validator to provide a more detailled analysis of the code.

gallandarakhneorg added a commit that referenced this issue Jun 20, 2020
see #1014

Signed-off-by: Stéphane Galland <galland@arakhne.org>
@gallandarakhneorg gallandarakhneorg changed the title Sychrnonization in behavior Sychronization in behavior Jun 22, 2020
@gallandarakhneorg gallandarakhneorg self-assigned this Jun 22, 2020
@gallandarakhneorg gallandarakhneorg modified the milestones: 0.12.0, 0.14.0 Oct 12, 2020
@gallandarakhneorg gallandarakhneorg removed their assignment Sep 21, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants