{"action":"created","issue":{"url":"https://api.github.com/repos/orocos-toolchain/rtt/issues/170","repository_url":"https://api.github.com/repos/orocos-toolchain/rtt","labels_url":"https://api.github.com/repos/orocos-toolchain/rtt/issues/170/labels{/name}","comments_url":"https://api.github.com/repos/orocos-toolchain/rtt/issues/170/comments","events_url":"https://api.github.com/repos/orocos-toolchain/rtt/issues/170/events","html_url":"https://github.com/orocos-toolchain/rtt/issues/170","id":174422890,"number":170,"title":"thread safety may be broken for OwnThread operations if sequential activity used","user":{"login":"pdima","id":1168590,"avatar_url":"https://avatars.githubusercontent.com/u/1168590?v=3","gravatar_id":"","url":"https://api.github.com/users/pdima","html_url":"https://github.com/pdima","followers_url":"https://api.github.com/users/pdima/followers","following_url":"https://api.github.com/users/pdima/following{/other_user}","gists_url":"https://api.github.com/users/pdima/gists{/gist_id}","starred_url":"https://api.github.com/users/pdima/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pdima/subscriptions","organizations_url":"https://api.github.com/users/pdima/orgs","repos_url":"https://api.github.com/users/pdima/repos","events_url":"https://api.github.com/users/pdima/events{/privacy}","received_events_url":"https://api.github.com/users/pdima/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":1,"created_at":"2016-09-01T02:33:31Z","updated_at":"2016-09-01T09:42:30Z","closed_at":null,"body":"I found the case when the promise is broken of OwnThread operations to be called in the thread safe way.\r\n\r\nI have a task with sequential activity with OwnThread operations and event ports.\r\n\r\nI found I can call OwnThread operations from task browser in the middle of update hook processing data from event port. I'd expect OwnThread operations to be serialized and called only after updateHook returned.\r\n\r\nIt's caused by SequentialActivity::thread() returning os::MainThread, so when operation is called from the main thread, OperationCallerInterface::isSend() returns false as the current thread matches activity thread even while activity is being triggered from another thread.\r\n\r\nI don't know what would be the appropriate fix for this, OperationCallerInterface::isSend() should check the actual active sequential activity thread instead of the default MainThread, but I don't know how to do this in a thread safe way.\r\n\r\nAnother possible not very nice workarounds:\r\n1) use a dummy thread for sequential activities so it never matches calling thread\r\n2) OperationCallerInterface::isSend() should return true for OwnThread operations of main thread activities\r\n\r\n"},"comment":{"url":"https://api.github.com/repos/orocos-toolchain/rtt/issues/comments/244029303","html_url":"https://github.com/orocos-toolchain/rtt/issues/170#issuecomment-244029303","issue_url":"https://api.github.com/repos/orocos-toolchain/rtt/issues/170","id":244029303,"user":{"login":"meyerj","id":2506837,"avatar_url":"https://avatars.githubusercontent.com/u/2506837?v=3","gravatar_id":"","url":"https://api.github.com/users/meyerj","html_url":"https://github.com/meyerj","followers_url":"https://api.github.com/users/meyerj/followers","following_url":"https://api.github.com/users/meyerj/following{/other_user}","gists_url":"https://api.github.com/users/meyerj/gists{/gist_id}","starred_url":"https://api.github.com/users/meyerj/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/meyerj/subscriptions","organizations_url":"https://api.github.com/users/meyerj/orgs","repos_url":"https://api.github.com/users/meyerj/repos","events_url":"https://api.github.com/users/meyerj/events{/privacy}","received_events_url":"https://api.github.com/users/meyerj/received_events","type":"User","site_admin":false},"created_at":"2016-09-01T09:42:30Z","updated_at":"2016-09-01T09:42:30Z","body":"Yes, I see the problem. This affects the [toolchain-2.9](https://github.com/orocos-toolchain/rtt/tree/toolchain-2.9) branch only due to the patch introduced in https://github.com/orocos-toolchain/rtt/commit/f5e1d78ed899b09dbdd933c2072ca25f1fd209d8.\r\n\r\nI remember that while working on the patch we had a variant where [RTT::base::ActivityInterface::thread()](http://orocos-toolchain.github.io/devel/documentation/rtt/toolchain-2.9/api/html/classRTT_1_1base_1_1ActivityInterface.html#a190329785c1c7e4a542db833402a7811) was allowed to return a null pointer for all activities where the executing thread cannot be known by design, like for `SequentialActivity` and `SlaveActivity` without a master. `isSend()` would always return true in that case. I am not sure anymore why this approach has been disregarded at the end. Returning `os::MainThread` in these cases is just a guess, which might be valid for unit tests or if the operation is called from the TaskBrowser, but not in most other applications."}}
{"actor":{"display_login":"meyerj"}}