{"action":"created","issue":{"url":"https://api.github.com/repos/robotology/yarp/issues/609","labels_url":"https://api.github.com/repos/robotology/yarp/issues/609/labels{/name}","comments_url":"https://api.github.com/repos/robotology/yarp/issues/609/comments","events_url":"https://api.github.com/repos/robotology/yarp/issues/609/events","html_url":"https://github.com/robotology/yarp/pull/609","id":111387169,"number":609,"title":"Fix clock","user":{"login":"barbalberto","id":4061020,"avatar_url":"https://avatars.githubusercontent.com/u/4061020?v=3","gravatar_id":"","url":"https://api.github.com/users/barbalberto","html_url":"https://github.com/barbalberto","followers_url":"https://api.github.com/users/barbalberto/followers","following_url":"https://api.github.com/users/barbalberto/following{/other_user}","gists_url":"https://api.github.com/users/barbalberto/gists{/gist_id}","starred_url":"https://api.github.com/users/barbalberto/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/barbalberto/subscriptions","organizations_url":"https://api.github.com/users/barbalberto/orgs","repos_url":"https://api.github.com/users/barbalberto/repos","events_url":"https://api.github.com/users/barbalberto/events{/privacy}","received_events_url":"https://api.github.com/users/barbalberto/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/robotology/yarp/labels/Component:%20YARP_OS","name":"Component: YARP_OS","color":"207de5"},{"url":"https://api.github.com/repos/robotology/yarp/labels/Severity:%20Major","name":"Severity: Major","color":"e11d21"},{"url":"https://api.github.com/repos/robotology/yarp/labels/Status:%20In%20Progress","name":"Status: In Progress","color":"ededed"},{"url":"https://api.github.com/repos/robotology/yarp/labels/Type:%20Bug","name":"Type: Bug","color":"fc2929"}],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":7,"created_at":"2015-10-14T12:27:22Z","updated_at":"2015-10-15T09:26:01Z","closed_at":null,"pull_request":{"url":"https://api.github.com/repos/robotology/yarp/pulls/609","html_url":"https://github.com/robotology/yarp/pull/609","diff_url":"https://github.com/robotology/yarp/pull/609.diff","patch_url":"https://github.com/robotology/yarp/pull/609.patch"},"body":"My proposal to fix the crash when calling UseSystemClock.\r\n\r\n3 commit introducing one change each, two of them are needed to fix the issue while the third one is optional.\r\n\r\n- Commit: Add 'if(!closing)':  *needed*\r\n **ratio**: while closing, the destructor is already called, so the  queue of waiting threads has already been deleted once. This is deleting an already delete structure so must be avoided.\r\n\r\n- Commit: Mutex static:  *needed*\r\n  **ratio**:  functions like delay(sec) sleep on a ```waiter.second->wait();```\r\n   If they woke up because of a call to ```UseSystemClock```, they actually restart running 'inside' a member function of a class whose destructor has already been called. The first thing they do is taking the mutex, which is already destroyed. This commit makes the mutexs static so their life span can survive the calls of the NetworkClock destructor and does not crash. \r\n  **Caution**: Changing to static makes a lot of differences, not only the lifespan, so maybe this can actually introduce some impredicted behaviour. From my point of view, since there is always only one clock for an application, the side effect of having a static member should not make any difference, but I'd like some feedback on this.\r\n\r\n- Commit: 'add getClock'  -- *optional*\r\n  When calling UseNetworkClock, the clock is not actually instantiated untill it is used the for first time. This force the clock to be created before returning from the UseNetworkClock function, so avoiding possible races between a thread calling this function and another calling the getClock(). I don't think this will actually create any problems bbut I feel safer this way.\r\n"},"comment":{"url":"https://api.github.com/repos/robotology/yarp/issues/comments/148329387","html_url":"https://github.com/robotology/yarp/pull/609#issuecomment-148329387","issue_url":"https://api.github.com/repos/robotology/yarp/issues/609","id":148329387,"user":{"login":"barbalberto","id":4061020,"avatar_url":"https://avatars.githubusercontent.com/u/4061020?v=3","gravatar_id":"","url":"https://api.github.com/users/barbalberto","html_url":"https://github.com/barbalberto","followers_url":"https://api.github.com/users/barbalberto/followers","following_url":"https://api.github.com/users/barbalberto/following{/other_user}","gists_url":"https://api.github.com/users/barbalberto/gists{/gist_id}","starred_url":"https://api.github.com/users/barbalberto/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/barbalberto/subscriptions","organizations_url":"https://api.github.com/users/barbalberto/orgs","repos_url":"https://api.github.com/users/barbalberto/repos","events_url":"https://api.github.com/users/barbalberto/events{/privacy}","received_events_url":"https://api.github.com/users/barbalberto/received_events","type":"User","site_admin":false},"created_at":"2015-10-15T09:26:01Z","updated_at":"2015-10-15T09:26:01Z","body":"About the delete, you are right, I overlooked at it, I'll fix it asap. Thanks!\r\nNow that we point it out, having a semaphore to be *created* and *destroyed* each time we call a delay function isn't a bit heavy on performances?"}}