{"action":"created","issue":{"url":"https://api.github.com/repos/manastech/crystal/issues/1399","labels_url":"https://api.github.com/repos/manastech/crystal/issues/1399/labels{/name}","comments_url":"https://api.github.com/repos/manastech/crystal/issues/1399/comments","events_url":"https://api.github.com/repos/manastech/crystal/issues/1399/events","html_url":"https://github.com/manastech/crystal/pull/1399","id":105120483,"number":1399,"title":"Add Singleton Module.","user":{"login":"technorama","id":51043,"avatar_url":"https://avatars.githubusercontent.com/u/51043?v=3","gravatar_id":"","url":"https://api.github.com/users/technorama","html_url":"https://github.com/technorama","followers_url":"https://api.github.com/users/technorama/followers","following_url":"https://api.github.com/users/technorama/following{/other_user}","gists_url":"https://api.github.com/users/technorama/gists{/gist_id}","starred_url":"https://api.github.com/users/technorama/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/technorama/subscriptions","organizations_url":"https://api.github.com/users/technorama/orgs","repos_url":"https://api.github.com/users/technorama/repos","events_url":"https://api.github.com/users/technorama/events{/privacy}","received_events_url":"https://api.github.com/users/technorama/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":24,"created_at":"2015-09-06T22:28:48Z","updated_at":"2015-10-23T00:23:05Z","closed_at":null,"pull_request":{"url":"https://api.github.com/repos/manastech/crystal/pulls/1399","html_url":"https://github.com/manastech/crystal/pull/1399","diff_url":"https://github.com/manastech/crystal/pull/1399.diff","patch_url":"https://github.com/manastech/crystal/pull/1399.patch"},"body":""},"comment":{"url":"https://api.github.com/repos/manastech/crystal/issues/comments/150393798","html_url":"https://github.com/manastech/crystal/pull/1399#issuecomment-150393798","issue_url":"https://api.github.com/repos/manastech/crystal/issues/1399","id":150393798,"user":{"login":"waj","id":22697,"avatar_url":"https://avatars.githubusercontent.com/u/22697?v=3","gravatar_id":"","url":"https://api.github.com/users/waj","html_url":"https://github.com/waj","followers_url":"https://api.github.com/users/waj/followers","following_url":"https://api.github.com/users/waj/following{/other_user}","gists_url":"https://api.github.com/users/waj/gists{/gist_id}","starred_url":"https://api.github.com/users/waj/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/waj/subscriptions","organizations_url":"https://api.github.com/users/waj/orgs","repos_url":"https://api.github.com/users/waj/repos","events_url":"https://api.github.com/users/waj/events{/privacy}","received_events_url":"https://api.github.com/users/waj/received_events","type":"User","site_admin":false},"created_at":"2015-10-23T00:23:05Z","updated_at":"2015-10-23T00:23:05Z","body":"Again, I like the Singleton module and I want it in the standard library. I just wont use it for internal runtime stuff. Just let it be for end users of the language. I'd probably even make the SignalHandler a module and use class variables (there is a mix of class and instance variables right now that I'm not sure if it was intentional).\r\n\r\nAnyway, something **much** more important: the current implementation is broken. Well... actually `Mutex` is broken, because they lock forever when synchronizing from the same fiber. Maybe #1612 can be used to fix this? I don't think so... this might need some more work because we need it to play nice with fibers on a single thread before moving to multiple threads.\r\n\r\nThis example hangs forever and never print anything:\r\n\r\n```crystal\r\nclass Foo\r\n  include Singleton\r\n\r\n  def initialize\r\n    sleep 1\r\n  end\r\nend\r\n\r\nspawn { puts Foo.instance }\r\nspawn { puts Foo.instance }\r\n\r\nsleep 5\r\n```\r\n\r\nMaybe I should open a separate issue for this, but basically the `Mutex#syncrhonize` would need to `try_lock` and if it fails, the current fiber must be saved in a queue and reschedule while unlocking, plus some minor details that I'm probably omitting right now. Is there any other way around this problem?"}}