Re: Static constructor

2021-01-18 Thread ludo via Digitalmars-d-learn
The mutex isn't more "global", it's more "local" (although, this will make it shared). Yes shared, this is what I meant by global :) Thanks, it's clearer now.

Re: Static constructor

2021-01-18 Thread Steven Schveighoffer via Digitalmars-d-learn
On 1/17/21 6:54 PM, ludo wrote: Yes alright. I think the dev made a design mistake because he called synchronized( OpenAL.mutex ) when it should be more of a global, non OpenAL specific, mutex. I mean in the code there were things like (pseudo-code) --- System {   private int[] buffer  

Re: Static constructor

2021-01-17 Thread ludo via Digitalmars-d-learn
Thanks, as explained I am indeed porting old code. No on the AA (as noted above). The mutex *is* created on demand. Every Object can have a mutex, and it's only created when you synchronize it for the first time. Yes alright. I think the dev made a design mistake because he called

Re: Static constructor

2021-01-15 Thread Steven Schveighoffer via Digitalmars-d-learn
On 1/6/21 12:05 PM, ludo wrote: I read in the documentation "Static constructors are used to initialize static class members with values that cannot be computed at compile time" I try to understand the design of the following code: --- class OpenAL { static string[int] ALErrorLookup;   

Re: Static constructor

2021-01-15 Thread Imperatorn via Digitalmars-d-learn
On Friday, 15 January 2021 at 16:04:02 UTC, ludo wrote: I believe so. I've never used OpenAL so it may have additional restrictions with multithreading, but from a simple "This function is only ever executed on one thread at a time", your above suggestions should work. Apologies for the late

Re: Static constructor

2021-01-15 Thread ludo via Digitalmars-d-learn
I believe so. I've never used OpenAL so it may have additional restrictions with multithreading, but from a simple "This function is only ever executed on one thread at a time", your above suggestions should work. Apologies for the late reply. No worry and thank you. I found the low-lock

Re: Static constructor

2021-01-14 Thread SealabJaster via Digitalmars-d-learn
On Tuesday, 12 January 2021 at 11:28:12 UTC, ludo wrote: Ok, I agree that ends up being a kind of strange singleton. But yes it was D v1 code. Do we agree that the following multi-threaded singleton pattern is the proper way as of today. It looks fine to me. The D wiki has the following

Re: Static constructor

2021-01-12 Thread ludo via Digitalmars-d-learn
NOTE : the entire code we are talking about is in the tiny url in my previous post. On Thursday, 7 January 2021 at 01:55:07 UTC, SealabJaster wrote: On Wednesday, 6 January 2021 at 17:05:02 UTC, ludo wrote: ... Using a static class like this seems to mostly be a design decision. So in

Re: Static constructor

2021-01-06 Thread SealabJaster via Digitalmars-d-learn
On Thursday, 7 January 2021 at 01:55:07 UTC, SealabJaster wrote: ... And on a side note, I don't believe this code is working as the author intends. Someone correct me if I'm wrong, but `static` variables in D arethread-local, so a `static Object mutex` wouldn't actually be visible

Re: Static constructor

2021-01-06 Thread SealabJaster via Digitalmars-d-learn
On Wednesday, 6 January 2021 at 17:05:02 UTC, ludo wrote: ... Using a static class like this seems to mostly be a design decision. i.e. instead of using something like ``` openalGetMutex(); // OR OpenAL openal = ...; openal.getMutex(); // OR I guess even this g_openal.getMutex(); ```

Re: Static constructor

2021-01-06 Thread Imperatorn via Digitalmars-d-learn
On Wednesday, 6 January 2021 at 17:05:02 UTC, ludo wrote: I read in the documentation "Static constructors are used to initialize static class members with values that cannot be computed at compile time" [...] Since this is not the complete code it's a bit hard to know, but I'd guess this

Re: static constructor not working with WinMain GUI app

2010-11-24 Thread Andrej Mitrovic
This means the windows sample code that comes with DMD in the samples folder has to be updated, that's where I took the template from. Thanks. On 11/23/10, Simen kjaeraas simen.kja...@gmail.com wrote: Andrej Mitrovic n...@none.none wrote: maintest.def: EXETYPE NT SUBSYSTEM WINDOWS

Re: static constructor not working with WinMain GUI app

2010-11-24 Thread Andrej Mitrovic
Ok I've filed a bug report and the fix: http://d.puremagic.com/issues/show_bug.cgi?id=5268 On 11/24/10, Andrej Mitrovic andrej.mitrov...@gmail.com wrote: This means the windows sample code that comes with DMD in the samples folder has to be updated, that's where I took the template from.

Re: static constructor not working with WinMain GUI app

2010-11-23 Thread Simen kjaeraas
Andrej Mitrovic n...@none.none wrote: maintest.def: EXETYPE NT SUBSYSTEM WINDOWS maintest.d: http://pastebin.com/3c4CKDG1 Compiled with DMD 2.050: dmd maintest.d maintest.def The output in the log file is Lenght: 0. The static constructor is never called when using WinMain. But if I use

Re: static constructor not working with WinMain GUI app

2010-11-23 Thread Michal Minich
On Tue, 23 Nov 2010 15:23:12 -0500, Andrej Mitrovic wrote: The static constructor is never called when using WinMain. Make sure you use newest DMD, I think in 2.048 or 49 there was bug that module constructors were not called.