Thread overview |
---|
October 23, 2013 Threading / Concurrency Problem | ||||
---|---|---|---|---|
| ||||
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 Re: Threading / Concurrency Problem | ||||
---|---|---|---|---|
| ||||
Posted in reply to Bauss | 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 Re: Threading / Concurrency Problem | ||||
---|---|---|---|---|
| ||||
Posted in reply to Meta | 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 Re: Threading / Concurrency Problem | ||||
---|---|---|---|---|
| ||||
Posted in reply to Bauss | 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.
|
Copyright © 1999-2021 by the D Language Foundation