{"action":"created","issue":{"url":"https://api.github.com/repos/spark/firmware/issues/614","labels_url":"https://api.github.com/repos/spark/firmware/issues/614/labels{/name}","comments_url":"https://api.github.com/repos/spark/firmware/issues/614/comments","events_url":"https://api.github.com/repos/spark/firmware/issues/614/events","html_url":"https://github.com/spark/firmware/pull/614","id":106426949,"number":614,"title":"Photon Multithreading ","user":{"login":"m-mcgowan","id":2465470,"avatar_url":"https://avatars.githubusercontent.com/u/2465470?v=3","gravatar_id":"","url":"https://api.github.com/users/m-mcgowan","html_url":"https://github.com/m-mcgowan","followers_url":"https://api.github.com/users/m-mcgowan/followers","following_url":"https://api.github.com/users/m-mcgowan/following{/other_user}","gists_url":"https://api.github.com/users/m-mcgowan/gists{/gist_id}","starred_url":"https://api.github.com/users/m-mcgowan/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/m-mcgowan/subscriptions","organizations_url":"https://api.github.com/users/m-mcgowan/orgs","repos_url":"https://api.github.com/users/m-mcgowan/repos","events_url":"https://api.github.com/users/m-mcgowan/events{/privacy}","received_events_url":"https://api.github.com/users/m-mcgowan/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/spark/firmware/labels/in%20progress","name":"in progress","color":"207de5"}],"state":"open","locked":false,"assignee":null,"milestone":{"url":"https://api.github.com/repos/spark/firmware/milestones/11","html_url":"https://github.com/spark/firmware/milestones/0.4.6","labels_url":"https://api.github.com/repos/spark/firmware/milestones/11/labels","id":1268393,"number":11,"title":"0.4.6","description":null,"creator":{"login":"m-mcgowan","id":2465470,"avatar_url":"https://avatars.githubusercontent.com/u/2465470?v=3","gravatar_id":"","url":"https://api.github.com/users/m-mcgowan","html_url":"https://github.com/m-mcgowan","followers_url":"https://api.github.com/users/m-mcgowan/followers","following_url":"https://api.github.com/users/m-mcgowan/following{/other_user}","gists_url":"https://api.github.com/users/m-mcgowan/gists{/gist_id}","starred_url":"https://api.github.com/users/m-mcgowan/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/m-mcgowan/subscriptions","organizations_url":"https://api.github.com/users/m-mcgowan/orgs","repos_url":"https://api.github.com/users/m-mcgowan/repos","events_url":"https://api.github.com/users/m-mcgowan/events{/privacy}","received_events_url":"https://api.github.com/users/m-mcgowan/received_events","type":"User","site_admin":false},"open_issues":15,"closed_issues":4,"state":"open","created_at":"2015-08-23T22:45:17Z","updated_at":"2015-09-15T17:32:27Z","due_on":null,"closed_at":null},"comments":3,"created_at":"2015-09-14T20:59:52Z","updated_at":"2015-09-15T18:22:53Z","closed_at":null,"pull_request":{"url":"https://api.github.com/repos/spark/firmware/pulls/614","html_url":"https://github.com/spark/firmware/pull/614","diff_url":"https://github.com/spark/firmware/pull/614.diff","patch_url":"https://github.com/spark/firmware/pull/614.patch"},"body":"This is an alpha of the Photon multithreading code.\r\n\r\nKnown issues:\r\n- sockets are not thread safe, so using a socket from the application loop may have unexpected behavior.\r\n- not investigated for memory leaks \r\n"},"comment":{"url":"https://api.github.com/repos/spark/firmware/issues/comments/140489823","html_url":"https://github.com/spark/firmware/pull/614#issuecomment-140489823","issue_url":"https://api.github.com/repos/spark/firmware/issues/614","id":140489823,"user":{"login":"monkbroc","id":1919681,"avatar_url":"https://avatars.githubusercontent.com/u/1919681?v=3","gravatar_id":"","url":"https://api.github.com/users/monkbroc","html_url":"https://github.com/monkbroc","followers_url":"https://api.github.com/users/monkbroc/followers","following_url":"https://api.github.com/users/monkbroc/following{/other_user}","gists_url":"https://api.github.com/users/monkbroc/gists{/gist_id}","starred_url":"https://api.github.com/users/monkbroc/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/monkbroc/subscriptions","organizations_url":"https://api.github.com/users/monkbroc/orgs","repos_url":"https://api.github.com/users/monkbroc/repos","events_url":"https://api.github.com/users/monkbroc/events{/privacy}","received_events_url":"https://api.github.com/users/monkbroc/received_events","type":"User","site_admin":false},"created_at":"2015-09-15T18:22:53Z","updated_at":"2015-09-15T18:22:53Z","body":"Sure thing Matt.\r\n\r\nReading your docs gist I expect that the biggest issue with existing user code will be in peripheral drivers that bang bits to pins because the pre-emptive round-robin scheduler will introduce 1ms delays once in a while. It will be necessary to have some very big bold warnings about adding critical sections to the docs, forums, examples.\r\n\r\nAnother note is that posting a message to the application queue in Particle.subscribe will delay running that user function until the current loop() completes instead of interrupting the user's code and running it now. It's a semantic change that could break code that expects user functions to interrupt loop().\r\n\r\nOn a slightly different topic, any time I see delay() in embedded code I cringe. It makes it so much harder to add functionality when most of the loop time is already spent busy-waiting. I think that introducing system threading would present a good opportunity to start showing better patterns as you mentioned. The challenge is coming up with those good patterns in the first place (I certainly wouldn't call what I did with automotive RTOS good patterns!)"}}