{"action":"created","issue":{"url":"https://api.github.com/repos/openbabel/openbabel/issues/295","repository_url":"https://api.github.com/repos/openbabel/openbabel","labels_url":"https://api.github.com/repos/openbabel/openbabel/issues/295/labels{/name}","comments_url":"https://api.github.com/repos/openbabel/openbabel/issues/295/comments","events_url":"https://api.github.com/repos/openbabel/openbabel/issues/295/events","html_url":"https://github.com/openbabel/openbabel/pull/295","id":146360264,"number":295,"title":"thread_local storge for global variables with state","user":{"login":"dkoes","id":2342142,"avatar_url":"https://avatars.githubusercontent.com/u/2342142?v=3","gravatar_id":"","url":"https://api.github.com/users/dkoes","html_url":"https://github.com/dkoes","followers_url":"https://api.github.com/users/dkoes/followers","following_url":"https://api.github.com/users/dkoes/following{/other_user}","gists_url":"https://api.github.com/users/dkoes/gists{/gist_id}","starred_url":"https://api.github.com/users/dkoes/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dkoes/subscriptions","organizations_url":"https://api.github.com/users/dkoes/orgs","repos_url":"https://api.github.com/users/dkoes/repos","events_url":"https://api.github.com/users/dkoes/events{/privacy}","received_events_url":"https://api.github.com/users/dkoes/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":8,"created_at":"2016-04-06T16:05:20Z","updated_at":"2016-05-12T22:01:11Z","closed_at":null,"pull_request":{"url":"https://api.github.com/repos/openbabel/openbabel/pulls/295","html_url":"https://github.com/openbabel/openbabel/pull/295","diff_url":"https://github.com/openbabel/openbabel/pull/295.diff","patch_url":"https://github.com/openbabel/openbabel/pull/295.patch"},"body":"OpenBabel uses a number of global objects for performing various kinds of perception and these objects maintain state (mostly in the form of smarts patterns).  This introduces race conditions in a multithreaded program that can result in segmentation faults.  For example, if two instances of bond perception are called at the same time, one might zero out the match list in the smarts pattern while the other is reading it. \r\n\r\nI have spent many hours trying to work around this probably by guarding calls with locks or parallelizing with processes instead of threads, but since perception routines are called as needed, it can be quite difficult to get right and it really shouldn't be necessary.\r\n\r\nToday I realized that making these global variables thread local should solve all these problems (and stop pharmit from crashing).  **This means that openbabel needs to be compiled with -std=cx11.**  This patch should gracefully degrade into the old buggy behaviour if this isn't an option.\r\n\r\nNote I may not have caught all the global objects that need this fix, but I think I at least got the ones with smarts patterns.  Global declarations have been consolidated into mol.h and prefixed with a new macro THREAD_LOCAL."},"comment":{"url":"https://api.github.com/repos/openbabel/openbabel/issues/comments/218898845","html_url":"https://github.com/openbabel/openbabel/pull/295#issuecomment-218898845","issue_url":"https://api.github.com/repos/openbabel/openbabel/issues/295","id":218898845,"user":{"login":"ghutchis","id":41128,"avatar_url":"https://avatars.githubusercontent.com/u/41128?v=3","gravatar_id":"","url":"https://api.github.com/users/ghutchis","html_url":"https://github.com/ghutchis","followers_url":"https://api.github.com/users/ghutchis/followers","following_url":"https://api.github.com/users/ghutchis/following{/other_user}","gists_url":"https://api.github.com/users/ghutchis/gists{/gist_id}","starred_url":"https://api.github.com/users/ghutchis/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ghutchis/subscriptions","organizations_url":"https://api.github.com/users/ghutchis/orgs","repos_url":"https://api.github.com/users/ghutchis/repos","events_url":"https://api.github.com/users/ghutchis/events{/privacy}","received_events_url":"https://api.github.com/users/ghutchis/received_events","type":"User","site_admin":false},"created_at":"2016-05-12T22:01:11Z","updated_at":"2016-05-12T22:01:11Z","body":"I'm going to revisit once I cut the 2.4 release. I suspect the test failure is minor."}}