{"action":"created","issue":{"url":"https://api.github.com/repos/asenchi/scrolls/issues/66","repository_url":"https://api.github.com/repos/asenchi/scrolls","labels_url":"https://api.github.com/repos/asenchi/scrolls/issues/66/labels{/name}","comments_url":"https://api.github.com/repos/asenchi/scrolls/issues/66/comments","events_url":"https://api.github.com/repos/asenchi/scrolls/issues/66/events","html_url":"https://github.com/asenchi/scrolls/pull/66","id":56750676,"number":66,"title":"print is atomic instead of mutex so it works in threaded environs","user":{"login":"reidmix","id":12073,"avatar_url":"https://avatars.githubusercontent.com/u/12073?v=3","gravatar_id":"","url":"https://api.github.com/users/reidmix","html_url":"https://github.com/reidmix","followers_url":"https://api.github.com/users/reidmix/followers","following_url":"https://api.github.com/users/reidmix/following{/other_user}","gists_url":"https://api.github.com/users/reidmix/gists{/gist_id}","starred_url":"https://api.github.com/users/reidmix/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/reidmix/subscriptions","organizations_url":"https://api.github.com/users/reidmix/orgs","repos_url":"https://api.github.com/users/reidmix/repos","events_url":"https://api.github.com/users/reidmix/events{/privacy}","received_events_url":"https://api.github.com/users/reidmix/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":6,"created_at":"2015-02-06T00:12:21Z","updated_at":"2016-02-04T21:30:46Z","closed_at":"2015-03-20T19:59:35Z","pull_request":{"url":"https://api.github.com/repos/asenchi/scrolls/pulls/66","html_url":"https://github.com/asenchi/scrolls/pull/66","diff_url":"https://github.com/asenchi/scrolls/pull/66.diff","patch_url":"https://github.com/asenchi/scrolls/pull/66.patch"},"body":"When using multiple threads we are running into a scenario using SideKiq/SideTiq where the mutex in `Scrolls::Log#write` isn't doing what we expect.  Even with the mutex, it is not shared across threads, and in the following example, the two loglines are not being separated out with a newline as we'd expect:\r\n\r\n```\r\n2014-09-18T04:57:00.897495+00:00 54.80.127.117 local7.info app[worker.1]: - d.fdd8e8d0-048c-4667-9199-218114219753 sample#app.q.enqueued=0 sample#app.q.processed=1 sample#watchtower.q.failed=0 measure#app.q.latency=02014-09-18T04:57:00.897Z 2 TID-owg6kvhpo INFO: [Sidetiq] Enqueue: Stats (at: 1411016280.0) (last: 1411016220.0)\r\n```\r\n\r\nTo simplify the case, we can see that `puts` is not atomic:\r\n\r\n```\r\n1.9.3-p448 :015 >   10.times { Thread.new { puts \"hi\" }}\r\n => 10 \r\n1.9.3-p448 :016 > hihihihi\r\nhi\r\n\r\nhihi\r\n\r\n\r\nhi\r\nhihi\r\n```\r\n\r\nA solution is to use `print`, it is atomic and works as expected (even without the mutex):\r\n\r\n```\r\n1.9.3-p448 :016 > 10.times { Thread.new { print \"hi\\n\" }}\r\nhi\r\nhi\r\nhi\r\n => 10 \r\nhi\r\nhi\r\nhi\r\nhi\r\nhi\r\nhi\r\n```\r\n\r\nAdditionally, removing the `rescue` that was an artifact from an old refactor:\r\nhttps://github.com/asenchi/scrolls/commit/60e7220341cd02de006991d35934b1bd7f6f3cd2\r\n"},"comment":{"url":"https://api.github.com/repos/asenchi/scrolls/issues/comments/180060947","html_url":"https://github.com/asenchi/scrolls/pull/66#issuecomment-180060947","issue_url":"https://api.github.com/repos/asenchi/scrolls/issues/66","id":180060947,"user":{"login":"jmervine","id":837893,"avatar_url":"https://avatars.githubusercontent.com/u/837893?v=3","gravatar_id":"","url":"https://api.github.com/users/jmervine","html_url":"https://github.com/jmervine","followers_url":"https://api.github.com/users/jmervine/followers","following_url":"https://api.github.com/users/jmervine/following{/other_user}","gists_url":"https://api.github.com/users/jmervine/gists{/gist_id}","starred_url":"https://api.github.com/users/jmervine/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jmervine/subscriptions","organizations_url":"https://api.github.com/users/jmervine/orgs","repos_url":"https://api.github.com/users/jmervine/repos","events_url":"https://api.github.com/users/jmervine/events{/privacy}","received_events_url":"https://api.github.com/users/jmervine/received_events","type":"User","site_admin":false},"created_at":"2016-02-04T21:30:46Z","updated_at":"2016-02-04T21:30:46Z","body":"Mind updating @reidmix and I when when this is released?"}}