digitalmars.D.learn - Threading / Concurrency Problem
- Bauss (18/18) Oct 23 2013 Working on a 2nd simple webserver in D. However I am facing a
Working on a 2nd simple webserver in D. However I am facing a problem with some threading. I want the receiving of connections to happen in a 2nd thread, but after adding the connections to the collection it seems like the receive thread never loops through them, as if no connections were ever added. However I have checked and it is added. The thread for receiving is also working as I have checked if code outside of the foreach loop works and it does, so it's probably a problem with the collection. This makes me assume it's a concurrency issue and I'm not sure how to fix it. I'm using an associative array for the connections. Class[int] is the format I'm using. You can view my code here: If anyone knows the solution to this, it would be appreciated. I can't seem to figure it out. Code: http://pastebin.com/A61NPWUq
Oct 23 2013
On Wednesday, 23 October 2013 at 11:51:35 UTC, Bauss wrote:Working on a 2nd simple webserver in D. However I am facing a problem with some threading. I want the receiving of connections to happen in a 2nd thread, but after adding the connections to the collection it seems like the receive thread never loops through them, as if no connections were ever added. However I have checked and it is added. The thread for receiving is also working as I have checked if code outside of the foreach loop works and it does, so it's probably a problem with the collection. This makes me assume it's a concurrency issue and I'm not sure how to fix it. I'm using an associative array for the connections. Class[int] is the format I'm using. You can view my code here: If anyone knows the solution to this, it would be appreciated. I can't seem to figure it out. Code: http://pastebin.com/A61NPWUqPossibly try marking Connections as shared. I can't compile your example because it's missing import statements.
Oct 23 2013
On Wednesday, 23 October 2013 at 12:20:32 UTC, Meta wrote:On Wednesday, 23 October 2013 at 11:51:35 UTC, Bauss wrote:Thanks. It worked! :)Working on a 2nd simple webserver in D. However I am facing a problem with some threading. I want the receiving of connections to happen in a 2nd thread, but after adding the connections to the collection it seems like the receive thread never loops through them, as if no connections were ever added. However I have checked and it is added. The thread for receiving is also working as I have checked if code outside of the foreach loop works and it does, so it's probably a problem with the collection. This makes me assume it's a concurrency issue and I'm not sure how to fix it. I'm using an associative array for the connections. Class[int] is the format I'm using. You can view my code here: If anyone knows the solution to this, it would be appreciated. I can't seem to figure it out. Code: http://pastebin.com/A61NPWUqPossibly try marking Connections as shared. I can't compile your example because it's missing import statements.
Oct 23 2013
On Wednesday, 23 October 2013 at 12:41:58 UTC, Bauss wrote:Thanks. It worked! :)Connections is in thread local storage by default. If you want it to be global across threads, you have to mark it shared or __gshared.
Oct 23 2013