October 08, 2015 Re: Threading Questions | ||||
---|---|---|---|---|
| ||||
Posted in reply to Kagamin | On Wednesday, 7 October 2015 at 09:09:36 UTC, Kagamin wrote: > On Sunday, 4 October 2015 at 04:24:55 UTC, bitwise wrote: >> I use C#(garbage collected) for making apps/games, and while, _in_theory_, the GC is supposed to protect you from leaks, memory is not the only thing that can leak. Threads need to be stopped, graphics resources need to be released, etc. > > XNA doesn't manage graphics resources? > > On Monday, 5 October 2015 at 17:40:24 UTC, bitwise wrote: >> I'm not sure what's going to be done with shared, but I do think it's annoying that you can't do this: >> >> shared Array!int numbers; >> >> someThread... { >> numbers.clear(); // 'clear' is not shared >> } >> >> So this means that on top of the already ridiculous number of attributes D has, now you have to mark everything as shared too =/ > > That's illegal in other languages too except that they allow you to do it. If you want concurrent collections, you must code them separately: https://msdn.microsoft.com/en-us/library/system.collections.concurrent%28v=vs.110%29.aspx I'm not sure what you mean by illegal. AFAIK 'shared' is unique to D. As far as simply locking and then accessing a global variable(class static member) in C#, there is no problem doing that from multiple threads. If you have System.Collections.Generic.List(T) static class member, there is nothing wrong with using it from multiple threads like this: class Foo { static List<int> numbers = new List<int>(); void bar() { new Thread(()=>{ lock(numbers) { numbers.Add(1); }).Start(); } } Bit |
October 08, 2015 Re: Threading Questions | ||||
---|---|---|---|---|
| ||||
Posted in reply to bitwise | On Thursday, 8 October 2015 at 02:31:24 UTC, bitwise wrote:
> If you have System.Collections.Generic.List(T) static class member, there is nothing wrong with using it from multiple threads like this:
The equivalent of your D example would be
class Foo {
static List<int> numbers = new List<int>();
void bar() {
new Thread(()=>{
numbers.Add(1);
}).Start();
}
}
|
October 08, 2015 Re: Threading Questions | ||||
---|---|---|---|---|
| ||||
Posted in reply to Kagamin | On Thursday, 8 October 2015 at 10:11:38 UTC, Kagamin wrote:
> On Thursday, 8 October 2015 at 02:31:24 UTC, bitwise wrote:
>> If you have System.Collections.Generic.List(T) static class member, there is nothing wrong with using it from multiple threads like this:
>
> The equivalent of your D example would be
>
> class Foo {
> static List<int> numbers = new List<int>();
> void bar() {
> new Thread(()=>{
> numbers.Add(1);
> }).Start();
> }
> }
That still doesn't explain what you mean about it being illegal in other languages or why you brought up C# in the first place.
Bit
|
October 08, 2015 Re: Threading Questions | ||||
---|---|---|---|---|
| ||||
Posted in reply to bitwise | On Thursday, 8 October 2015 at 13:44:46 UTC, bitwise wrote:
> That still doesn't explain what you mean about it being illegal in other languages or why you brought up C# in the first place.
Illegal means the resulting program behaves incorrectly, potentially leading to silent failures and data corruption. C# is a language that allows such bugs, and D disallows them - treats such code as invalid and rejects.
|
October 09, 2015 Re: Threading Questions | ||||
---|---|---|---|---|
| ||||
Posted in reply to Kagamin | On Thursday, 8 October 2015 at 20:42:46 UTC, Kagamin wrote:
> On Thursday, 8 October 2015 at 13:44:46 UTC, bitwise wrote:
>> That still doesn't explain what you mean about it being illegal in other languages or why you brought up C# in the first place.
>
> Illegal means the resulting program behaves incorrectly, potentially leading to silent failures and data corruption. C# is a language that allows such bugs, and D disallows them - treats such code as invalid and rejects.
Ah, I see. I thought you meant illegal meant it won't compile. Wouldn't it be more correct to say that it's undefined behaviour?
Bit
|
October 09, 2015 Re: Threading Questions | ||||
---|---|---|---|---|
| ||||
Posted in reply to bitwise | On Friday, 9 October 2015 at 04:04:42 UTC, bitwise wrote:
> Ah, I see. I thought you meant illegal meant it won't compile. Wouldn't it be more correct to say that it's undefined behaviour?
I's probably not as undefined as in C case, i.e. it doesn't break safety guarantees, only the application's high-level business logic gets confused by data races.
|
Copyright © 1999-2021 by the D Language Foundation