{"action":"created","issue":{"url":"https://api.github.com/repos/tklab-tud/uscxml/issues/101","repository_url":"https://api.github.com/repos/tklab-tud/uscxml","labels_url":"https://api.github.com/repos/tklab-tud/uscxml/issues/101/labels{/name}","comments_url":"https://api.github.com/repos/tklab-tud/uscxml/issues/101/comments","events_url":"https://api.github.com/repos/tklab-tud/uscxml/issues/101/events","html_url":"https://github.com/tklab-tud/uscxml/issues/101","id":195803454,"number":101,"title":"Problem: Debouncing through step(blockMS) with blockMs = numerical_limits<size_t>::max doesnt work","user":{"login":"gabm","id":482105,"avatar_url":"https://avatars.githubusercontent.com/u/482105?v=3","gravatar_id":"","url":"https://api.github.com/users/gabm","html_url":"https://github.com/gabm","followers_url":"https://api.github.com/users/gabm/followers","following_url":"https://api.github.com/users/gabm/following{/other_user}","gists_url":"https://api.github.com/users/gabm/gists{/gist_id}","starred_url":"https://api.github.com/users/gabm/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/gabm/subscriptions","organizations_url":"https://api.github.com/users/gabm/orgs","repos_url":"https://api.github.com/users/gabm/repos","events_url":"https://api.github.com/users/gabm/events{/privacy}","received_events_url":"https://api.github.com/users/gabm/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":1,"created_at":"2016-12-15T13:19:15Z","updated_at":"2016-12-15T15:22:23Z","closed_at":null,"body":"Debouncing `step` with the default value of `step(std::numerical_limits<size_t>::max())` doesn't work.\r\n\r\nThe reason is because `size_t` is an `unsigned long` while the representation of std::chrono::milliseconds is `int64` on my system. So we basically get an overflow while calculating the `endTime` which probably lies in the past. This corrupted value of `unsigned long` is then used straight away in BasicEventQueue.cpp`: \r\n\r\n```\r\nauto endTime = std::chrono::system_clock::now() + std::chrono::milliseconds(blockMs);\r\nwhile (endTime > std::chrono::system_clock::now() && _queue.empty()) {\r\n    _cond.wait_until(_mutex, endTime);\r\n}\r\n```\r\n\r\nPossible Solutions:\r\n- define a sane max value (1e6 msec or more). That would work in any case..\r\n- make the max value dependent on the representation of std::chrono::system_clock (that would introduce chrono dependency)\r\n- use std::chrono::system_clock::duration::max() right away as default value\r\n\r\nI'd go with the last option, what do you think @sradomski ?\r\n"},"comment":{"url":"https://api.github.com/repos/tklab-tud/uscxml/issues/comments/267354082","html_url":"https://github.com/tklab-tud/uscxml/issues/101#issuecomment-267354082","issue_url":"https://api.github.com/repos/tklab-tud/uscxml/issues/101","id":267354082,"user":{"login":"sradomski","id":980655,"avatar_url":"https://avatars.githubusercontent.com/u/980655?v=3","gravatar_id":"","url":"https://api.github.com/users/sradomski","html_url":"https://github.com/sradomski","followers_url":"https://api.github.com/users/sradomski/followers","following_url":"https://api.github.com/users/sradomski/following{/other_user}","gists_url":"https://api.github.com/users/sradomski/gists{/gist_id}","starred_url":"https://api.github.com/users/sradomski/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/sradomski/subscriptions","organizations_url":"https://api.github.com/users/sradomski/orgs","repos_url":"https://api.github.com/users/sradomski/repos","events_url":"https://api.github.com/users/sradomski/events{/privacy}","received_events_url":"https://api.github.com/users/sradomski/received_events","type":"User","site_admin":false},"created_at":"2016-12-15T15:22:23Z","updated_at":"2016-12-15T15:22:23Z","body":"I'd very much like to avoid any dependency on `<chrono>` in `Interpreter.h` as the file is subjected to SWIG for the language bindings and I'd like to keep them as conservative as possible. What about checking blockMs in dequeue and limiting endTime to `std::chrono::system_clock::time_point::max()`, would that work?\r\n\r\n    if (blockMs > 0) {\r\n        using namespace std::chrono;\r\n\r\n        system_clock::time_point now = system_clock::now();\r\n        system_clock::time_point endTime = now + milliseconds(blockMs);\r\n\r\n        // now + milliseconds(blockMs) may not have fitted into a duration type - limit to maximum duration\r\n        if (blockMs > system_clock::duration::max().count() - duration_cast<milliseconds>(now.time_since_epoch()).count()) {\r\n            endTime = system_clock::time_point::max();\r\n        }\r\n        \r\n        // block for given milliseconds or until queue is non-empty\r\n        while (endTime > std::chrono::system_clock::now() && _queue.empty()) {\r\n            _cond.wait_until(_mutex, endTime);\r\n        }\r\n    }"}}
{"actor":{"display_login":"sradomski"}}