Thread overview
Threading / Concurrency Problem
Oct 23, 2013
Bauss
Oct 23, 2013
Meta
Oct 23, 2013
Bauss
Oct 24, 2013
Meta
October 23, 2013
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
October 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/A61NPWUq

Possibly try marking Connections as shared. I can't compile your example because it's missing import statements.
October 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:
>> 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
>
> Possibly try marking Connections as shared. I can't compile your example because it's missing import statements.


Thanks. It worked! :)
October 24, 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.