{"action":"created","issue":{"url":"https://api.github.com/repos/marekjm/viuavm/issues/121","repository_url":"https://api.github.com/repos/marekjm/viuavm","labels_url":"https://api.github.com/repos/marekjm/viuavm/issues/121/labels{/name}","comments_url":"https://api.github.com/repos/marekjm/viuavm/issues/121/comments","events_url":"https://api.github.com/repos/marekjm/viuavm/issues/121/events","html_url":"https://github.com/marekjm/viuavm/issues/121","id":131781287,"number":121,"title":"Watchdog thread","user":{"login":"marekjm","id":2565699,"avatar_url":"https://avatars.githubusercontent.com/u/2565699?v=3","gravatar_id":"","url":"https://api.github.com/users/marekjm","html_url":"https://github.com/marekjm","followers_url":"https://api.github.com/users/marekjm/followers","following_url":"https://api.github.com/users/marekjm/following{/other_user}","gists_url":"https://api.github.com/users/marekjm/gists{/gist_id}","starred_url":"https://api.github.com/users/marekjm/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/marekjm/subscriptions","organizations_url":"https://api.github.com/users/marekjm/orgs","repos_url":"https://api.github.com/users/marekjm/repos","events_url":"https://api.github.com/users/marekjm/events{/privacy}","received_events_url":"https://api.github.com/users/marekjm/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/marekjm/viuavm/labels/enhancement","name":"enhancement","color":"84b6eb"},{"url":"https://api.github.com/repos/marekjm/viuavm/labels/experimental","name":"experimental","color":"5359e7"},{"url":"https://api.github.com/repos/marekjm/viuavm/labels/feature","name":"feature","color":"006b75"}],"state":"open","locked":false,"assignee":{"login":"marekjm","id":2565699,"avatar_url":"https://avatars.githubusercontent.com/u/2565699?v=3","gravatar_id":"","url":"https://api.github.com/users/marekjm","html_url":"https://github.com/marekjm","followers_url":"https://api.github.com/users/marekjm/followers","following_url":"https://api.github.com/users/marekjm/following{/other_user}","gists_url":"https://api.github.com/users/marekjm/gists{/gist_id}","starred_url":"https://api.github.com/users/marekjm/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/marekjm/subscriptions","organizations_url":"https://api.github.com/users/marekjm/orgs","repos_url":"https://api.github.com/users/marekjm/repos","events_url":"https://api.github.com/users/marekjm/events{/privacy}","received_events_url":"https://api.github.com/users/marekjm/received_events","type":"User","site_admin":false},"milestone":{"url":"https://api.github.com/repos/marekjm/viuavm/milestones/1","html_url":"https://github.com/marekjm/viuavm/milestones/Release%201.0","labels_url":"https://api.github.com/repos/marekjm/viuavm/milestones/1/labels","id":933805,"number":1,"title":"Release 1.0","description":"First useable release.","creator":{"login":"marekjm","id":2565699,"avatar_url":"https://avatars.githubusercontent.com/u/2565699?v=3","gravatar_id":"","url":"https://api.github.com/users/marekjm","html_url":"https://github.com/marekjm","followers_url":"https://api.github.com/users/marekjm/followers","following_url":"https://api.github.com/users/marekjm/following{/other_user}","gists_url":"https://api.github.com/users/marekjm/gists{/gist_id}","starred_url":"https://api.github.com/users/marekjm/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/marekjm/subscriptions","organizations_url":"https://api.github.com/users/marekjm/orgs","repos_url":"https://api.github.com/users/marekjm/repos","events_url":"https://api.github.com/users/marekjm/events{/privacy}","received_events_url":"https://api.github.com/users/marekjm/received_events","type":"User","site_admin":false},"open_issues":5,"closed_issues":6,"state":"open","created_at":"2015-01-13T17:37:30Z","updated_at":"2016-02-05T22:51:27Z","due_on":null,"closed_at":null},"comments":1,"created_at":"2016-02-05T22:51:27Z","updated_at":"2016-02-13T10:38:00Z","closed_at":null,"body":"Implement support for watchdog thread.\r\n\r\nCurrently, when an exception is thrown somewhere in code and reaches top of the stack (i.e. the thread is unable to handle the exception) machine shuts down, generates stack trace and informs the user what thread killed it and how the top-most frame looked like in the moment the exception has been generated.\r\n\r\nThe problem is that the *OH NOES, WHAT AR WE GONNA DO?!* approach to error handling is rarely the best one. Unfortunately, this *is* the approach employed by the machine in case of thread death. Watchdog thread would be provided by the programmer, and will handle thread deaths caused by runaway exceptions in a clean, elegant and predictable manner.\r\n\r\nThe thread should be idle most of the time, blocking on `receive` instruction. Every time a thread dies the watchdog receives a message from the VM containing two pieces of information:\r\n\r\n- beginning function of deceased thread,\r\n- the cause of thread's death (i.e. the exception that killed it),\r\n\r\nOther information may be provided in the future. The information provided by \"death messages\" is sufficient to log the cause of death of a thread, and restart it if necessary.\r\n\r\nThe watchdog itself is an immortal thread - even if it dies, the machine will automatically restart it. Any \"death messages\" generated between death and resurrection of the watchdog thread will be buffered by the VM. Such behaviour means that no message is lost, but the watchdog may be very busy shortly after resurrection. Watchdog thread may run at higher priority to account for this.\r\n\r\nIf the watchdog thread is not provided by the program, the falls back to the *OH NOES* approach to thread deaths.\r\n\r\n*Edit: renamed \"supervisor\" to \"watchdog\".*"},"comment":{"url":"https://api.github.com/repos/marekjm/viuavm/issues/comments/183640457","html_url":"https://github.com/marekjm/viuavm/issues/121#issuecomment-183640457","issue_url":"https://api.github.com/repos/marekjm/viuavm/issues/121","id":183640457,"user":{"login":"marekjm","id":2565699,"avatar_url":"https://avatars.githubusercontent.com/u/2565699?v=3","gravatar_id":"","url":"https://api.github.com/users/marekjm","html_url":"https://github.com/marekjm","followers_url":"https://api.github.com/users/marekjm/followers","following_url":"https://api.github.com/users/marekjm/following{/other_user}","gists_url":"https://api.github.com/users/marekjm/gists{/gist_id}","starred_url":"https://api.github.com/users/marekjm/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/marekjm/subscriptions","organizations_url":"https://api.github.com/users/marekjm/orgs","repos_url":"https://api.github.com/users/marekjm/repos","events_url":"https://api.github.com/users/marekjm/events{/privacy}","received_events_url":"https://api.github.com/users/marekjm/received_events","type":"User","site_admin":false},"created_at":"2016-02-13T10:38:00Z","updated_at":"2016-02-13T10:38:00Z","body":"Watchdog does not have to run at higher priority as it will be scheduled on-demand. When a thread dies, a watchdog thread is being executed until it suspends itself (i.e. blocks on `receive` instruction and has empty message queue).\r\n\r\nThis *until it suspends itself* bit means that the watchdog should not perform blocking operations. If it must do some I/O - let it spawn a writer thread for it. After all, Viua is pretty good at running many threads."}}