{"action":"created","issue":{"url":"https://api.github.com/repos/zeromq/jeromq/issues/116","repository_url":"https://api.github.com/repos/zeromq/jeromq","labels_url":"https://api.github.com/repos/zeromq/jeromq/issues/116/labels{/name}","comments_url":"https://api.github.com/repos/zeromq/jeromq/issues/116/comments","events_url":"https://api.github.com/repos/zeromq/jeromq/issues/116/events","html_url":"https://github.com/zeromq/jeromq/issues/116","id":23193202,"number":116,"title":"Remove Thread.interrupt() restriction.","user":{"login":"inscriber","id":1054763,"avatar_url":"https://avatars.githubusercontent.com/u/1054763?v=3","gravatar_id":"","url":"https://api.github.com/users/inscriber","html_url":"https://github.com/inscriber","followers_url":"https://api.github.com/users/inscriber/followers","following_url":"https://api.github.com/users/inscriber/following{/other_user}","gists_url":"https://api.github.com/users/inscriber/gists{/gist_id}","starred_url":"https://api.github.com/users/inscriber/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/inscriber/subscriptions","organizations_url":"https://api.github.com/users/inscriber/orgs","repos_url":"https://api.github.com/users/inscriber/repos","events_url":"https://api.github.com/users/inscriber/events{/privacy}","received_events_url":"https://api.github.com/users/inscriber/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":8,"created_at":"2013-11-23T20:09:24Z","updated_at":"2016-07-06T17:48:48Z","closed_at":null,"body":"The wiki says:\r\n\r\n\"Context.term() must be called before interrupting a thread by Thread.interrupt. Otherwise internal pipe which is used to signal ZMQ commands will be shutdown unexpectedly.\"\r\n\r\nHowever, in some cases this means that there is no clean way for an application to shut down when it is blocked on recv().\r\n\r\nConsider a thread (thread B) that is blocked on a socket's recv().\r\n\r\nSuppose the main thread (thread A) of the application wants to shut down, it needs to cleanly terminate thread B. This typically involves sending an interrupt to thread B to unblock, but wait! we need to call Context.term() first. However, the wiki says:\r\n\r\n\"Close all the sockets properly otherwise Context.term() will wait forever\"\r\n\r\nOK, we need to close the socket first, but wait! The ZMQ guide says:\r\n\r\n\"Isolate data privately within its thread and never share data in multiple threads. The only exception to this are ØMQ contexts, which are threadsafe.\"\r\n\r\nHmm, so the only safe way to close the socket is on the thread that is currently blocked (thread B), too bad we can't do that.\r\n\r\nSo now the only way for thread B to unblock is to wait for a new message or a timeout (which may have been set to no timeout). If there are no more messages and there is no timeout, the thread will be blocked indefinitely. But regardless, there should be a means to preemptively unblock the thread.\r\n\r\nEven if we were to ignore the shutdown problem, this restriction also leads to more awkward code because now the context needs to be exposed to other threads where it might not have been necessary without the restriction.\r\n\r\nIn fact, if you look at the Java example in the ZMQ guide and even the examples in this repository, it breaks the interrupt rule.\r\n\r\nThis is a pretty common pattern you see throughout the code:\r\n\r\n    while (!Thread.currentThread ().isInterrupted ()) {\r\n        ...\r\n    }\r\n    receiver.close ();\r\n    context.term ();\r\n\r\nNotice how it expects an interrupt before closing the socket and context."},"comment":{"url":"https://api.github.com/repos/zeromq/jeromq/issues/comments/230850844","html_url":"https://github.com/zeromq/jeromq/issues/116#issuecomment-230850844","issue_url":"https://api.github.com/repos/zeromq/jeromq/issues/116","id":230850844,"user":{"login":"barbaragomes","id":13023284,"avatar_url":"https://avatars.githubusercontent.com/u/13023284?v=3","gravatar_id":"","url":"https://api.github.com/users/barbaragomes","html_url":"https://github.com/barbaragomes","followers_url":"https://api.github.com/users/barbaragomes/followers","following_url":"https://api.github.com/users/barbaragomes/following{/other_user}","gists_url":"https://api.github.com/users/barbaragomes/gists{/gist_id}","starred_url":"https://api.github.com/users/barbaragomes/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/barbaragomes/subscriptions","organizations_url":"https://api.github.com/users/barbaragomes/orgs","repos_url":"https://api.github.com/users/barbaragomes/repos","events_url":"https://api.github.com/users/barbaragomes/events{/privacy}","received_events_url":"https://api.github.com/users/barbaragomes/received_events","type":"User","site_admin":false},"created_at":"2016-07-06T17:48:48Z","updated_at":"2016-07-06T17:48:48Z","body":"+1 It would be great if jeromq was Thread.interrupt safe. :)"}}
{"actor":{"display_login":"barbaragomes"}}