payload: {"action":"opened","issue":{"url":"https://api.github.com/repos/JuliaRobotics/RigidBodyDynamics.jl/issues/548","repository_url":"https://api.github.com/repos/JuliaRobotics/RigidBodyDynamics.jl","labels_url":"https://api.github.com/repos/JuliaRobotics/RigidBodyDynamics.jl/issues/548/labels{/name}","comments_url":"https://api.github.com/repos/JuliaRobotics/RigidBodyDynamics.jl/issues/548/comments","events_url":"https://api.github.com/repos/JuliaRobotics/RigidBodyDynamics.jl/issues/548/events","html_url":"https://github.com/JuliaRobotics/RigidBodyDynamics.jl/issues/548","id":442384849,"node_id":"MDU6SXNzdWU0NDIzODQ4NDk=","number":548,"title":"Issues using threading and StateCache's","user":{"login":"blandry","id":2207326,"node_id":"MDQ6VXNlcjIyMDczMjY=","avatar_url":"https://avatars0.githubusercontent.com/u/2207326?v=4","gravatar_id":"","url":"https://api.github.com/users/blandry","html_url":"https://github.com/blandry","followers_url":"https://api.github.com/users/blandry/followers","following_url":"https://api.github.com/users/blandry/following{/other_user}","gists_url":"https://api.github.com/users/blandry/gists{/gist_id}","starred_url":"https://api.github.com/users/blandry/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/blandry/subscriptions","organizations_url":"https://api.github.com/users/blandry/orgs","repos_url":"https://api.github.com/users/blandry/repos","events_url":"https://api.github.com/users/blandry/events{/privacy}","received_events_url":"https://api.github.com/users/blandry/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2019-05-09T19:00:52Z","updated_at":"2019-05-09T19:00:52Z","closed_at":null,"author_association":"CONTRIBUTOR","body":"I am trying to parallelize some computation and I think I am running into issues from the implementation of the `StateCache`. I am not sure if this stems from the fact the `StateCache` is multi-threaded itself or from some underlying data structure in `mechanism` that is shared across caches but this self-contained example works fine when the loop is run serially, but fails when multi-threaded. If you inspect the cache in this example the \"second\" one doesn't end up being set. \r\n\r\nA `deepcopy` of mechanism before passing it to the `StateCache` constructor doesn't help.\r\n\r\nThanks!\r\n\r\n```\r\nusing RigidBodyDynamics\r\nusing Base.Threads\r\nusing Distributed\r\n\r\nN = 2\r\n\r\nurdf = joinpath(dirname(pathof(RigidBodyDynamics)), \"..\", \"test\", \"urdf\", \"Acrobot.urdf\")\r\nmechanism = parse_urdf(urdf)\r\n\r\nsc = [StateCache(mechanism) for n = 1:N]\r\nqs = rand(num_positions(mechanism),N)\r\nvs = rand(num_velocities(mechanism),N)\r\n\r\n# for n = 1:N\r\n@threads for n = 1:N\r\n# @distributed for n = 1:N\r\n    state = sc[n][Float64]\r\n    set_configuration!(state, qs[:,n])\r\n    set_velocity!(state, vs[:,n])\r\n    setdirty!(state)\r\nend\r\n\r\n# println(qs)\r\n# for n = 1:N\r\n#     println(configuration(sc[n][Float64]))\r\n# end\r\n\r\nfor n = 1:N\r\n    @assert configuration(sc[n][Float64]) == qs[:,n]\r\nend\r\n\r\nfor n = 1:N\r\n    @assert velocity(sc[n][Float64]) == vs[:,n]\r\nend\r\n```\r\n"}}
other: {"actor":{"display_login":"blandry"}}