{"action":"created","issue":{"url":"https://api.github.com/repos/dotnet/orleans/issues/1710","repository_url":"https://api.github.com/repos/dotnet/orleans","labels_url":"https://api.github.com/repos/dotnet/orleans/issues/1710/labels{/name}","comments_url":"https://api.github.com/repos/dotnet/orleans/issues/1710/comments","events_url":"https://api.github.com/repos/dotnet/orleans/issues/1710/events","html_url":"https://github.com/dotnet/orleans/issues/1710","id":150775380,"number":1710,"title":"Invoke Grain's Method in 2 Threads,does the Method need Lock?","user":{"login":"liuchangtao","id":16682378,"avatar_url":"https://avatars.githubusercontent.com/u/16682378?v=3","gravatar_id":"","url":"https://api.github.com/users/liuchangtao","html_url":"https://github.com/liuchangtao","followers_url":"https://api.github.com/users/liuchangtao/followers","following_url":"https://api.github.com/users/liuchangtao/following{/other_user}","gists_url":"https://api.github.com/users/liuchangtao/gists{/gist_id}","starred_url":"https://api.github.com/users/liuchangtao/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/liuchangtao/subscriptions","organizations_url":"https://api.github.com/users/liuchangtao/orgs","repos_url":"https://api.github.com/users/liuchangtao/repos","events_url":"https://api.github.com/users/liuchangtao/events{/privacy}","received_events_url":"https://api.github.com/users/liuchangtao/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":10,"created_at":"2016-04-25T07:34:23Z","updated_at":"2016-04-25T14:21:25Z","closed_at":null,"body":"GrainA and GrainB\r\n\r\n--------------------------------------------------\r\n--------------------------------------------------\r\n\r\nGrainA has a Method like this:\r\n\r\npublic Task addFriend(int id)\r\n{\r\n     .....\r\n     m_friendList.Add(id);\r\n     ......\r\n}\r\n\r\n--------------------------------------------------\r\n--------------------------------------------------\r\n\r\nClient invoke the interface like this:\r\n\r\nvar ga = GrainClient.GrainFactory.GetGrain< IGrainA >(0);\r\nga.addFriend(111);\r\n\r\n--------------------------------------------------\r\n--------------------------------------------------\r\n\r\nGrainB has a Thread like this:\r\n\r\nvoid Thread1()\r\n{\r\n      while(true)\r\n    {\r\n         ...\r\n        var ga = GrainFactory.GetGrain< IGrainA >(0);\r\n        ga.addFriend(112);\r\n        ...\r\n    }\r\n}\r\n\r\n--------------------------------------------------\r\nGrainA and GrainB running in a silo，does the Method addFriend running in 2 Threads or not ？\r\n\r\nthank you very much ！\r\n"},"comment":{"url":"https://api.github.com/repos/dotnet/orleans/issues/comments/214357120","html_url":"https://github.com/dotnet/orleans/issues/1710#issuecomment-214357120","issue_url":"https://api.github.com/repos/dotnet/orleans/issues/1710","id":214357120,"user":{"login":"gabikliot","id":10171207,"avatar_url":"https://avatars.githubusercontent.com/u/10171207?v=3","gravatar_id":"","url":"https://api.github.com/users/gabikliot","html_url":"https://github.com/gabikliot","followers_url":"https://api.github.com/users/gabikliot/followers","following_url":"https://api.github.com/users/gabikliot/following{/other_user}","gists_url":"https://api.github.com/users/gabikliot/gists{/gist_id}","starred_url":"https://api.github.com/users/gabikliot/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/gabikliot/subscriptions","organizations_url":"https://api.github.com/users/gabikliot/orgs","repos_url":"https://api.github.com/users/gabikliot/repos","events_url":"https://api.github.com/users/gabikliot/events{/privacy}","received_events_url":"https://api.github.com/users/gabikliot/received_events","type":"User","site_admin":false},"created_at":"2016-04-25T14:21:25Z","updated_at":"2016-04-25T14:21:25Z","body":"For that case you can indeed use a thread in the thread pool. That would require synchronization between the grain code and the thread code, just like you have originally asked. \r\nBut a much better approach is to break this computation into smaller chunks and do all in the grain context. See more details in the last link I shared above."}}