Jump to content

dummzeuch

Members
  • Content Count

    1387
  • Joined

  • Last visited

  • Days Won

    45

Everything posted by dummzeuch

  1. I offered to help out and even submitted pull requests with updates for them, but they were ignored for several months. Then I gave up.
  2. I am reinventing the wheel again (yes, I like doing that). Can you see anything wrong with these SpinLock functions? (for Win32 only) ///<summary> /// simple spin lock function, Lk must have been initialized with 0 before first use </summary> procedure doLock(var _Lk: Integer); asm mov edx, eax mov ecx, 1 @Loop: mov eax, 0 lock cmpxchg dword ptr [edx], ecx jnz @Loop end; ///<summary> /// simple spin unlock function, Lk must have been initialized with 0 before first use </summary> procedure doUnLock(var _Lk: Integer); asm lock dec dword ptr[eax]; end; ///<summary> /// simple spin trylock function, Lk must have been initialized with 0 before first use /// @returns True if the lock could be acquired, False otherwise </summary> function doTryLock(var _Lk: Integer): Boolean; asm mov edx, eax mov ecx, 1 mov eax, 0 lock cmpxchg dword ptr [edx], ecx setz al end; doLock and doUnlock are taken from https://vitaliburkov.wordpress.com/2011/10/28/parallel-programming-with-delphi-part-ii-resolving-race-conditions/ doTryLock is based on doLock and uses the setz opcode to return a boolean rather than looping. I have done tests and they seem to work, but it's always difficult to actually test multi threaded code.
  3. If I remember correctly, it was added in Delphi 10.4, so it won't help much if you develop for multiple Delphi versions.
  4. dummzeuch

    spinlock primitives

    re 1: Then I probably need to repeat these tests on a system where the Delphi IDE hasn't run (yet), because I am not sure whether it had been running before the tests or not. re 2/3: There are lots of discussions on the web about Sleep(0) vs. Sleep(1) vs. SwitchToThread and there seems to be no definite answer which one to use in a spin lock. It all depends on the circumstances. re 4: Again, this depends on the circumstances. With a small protected section and low contention a spin lock might be way faster than a critical section. I was trying to find out whether that might solve some issues I had with a particular program. It turned out that it didn't (but again, I need to repeat the test taking into account what I have learned in the meantime), but this had started me into the topic.
  5. dummzeuch

    spinlock primitives

    Hm, shouldn't the assertion go into a constructor?
  6. dummzeuch

    spinlock primitives

    I read somewhere (when I was searching for 'Yield'), that Yield doesn't exist on Arm processors and there simply translates to NOP. Not sure whether I understood that correctly because at the time I wasn't really interested in Arm.
  7. dummzeuch

    spinlock primitives

    Yeah, right. Think again, Thomas. I did some tests and it turned out that in these tests(!) on my computer(!) Sleep(1) increased the throughput by more than 50% over Sleep(0), even though all threads were running in the same application and with the same priority: Sleep(0) 5 Writers 5 Readers Run1: Writes: 5738 Reads: 4683 [avg. per ms] Run2: Writes: 5662 Reads: 4716 [avg. per ms] Sleep(1) 5 Writers 5 Readers Run1: Writes: 10444 Reads: 7528 [avg. per ms] Run2: Writes: 8587 Reads: 9411 [avg. per ms] Note that it is quite possible that I bungled the tests. They are not as consistent as I would have expected.
  8. Actually I did less than a year ago: Compiling TeeChart 2020 for Delphi 2007 It won't help, of course.
  9. Unfortunately many well known commercial and open source libraries don't adhere to these. It's a major pain in the lower back every time I want to install Delphi on a new computer (which happens quite regularly, at least several times per year).
  10. I just tried to import a .NET assembly into the Delphi IDE: Component -> Import Compoent Select "Import .NET Assembly", press Next There I got a list of available assemblies, but that list is empty ??? Pressing "Add" and selecting the DLL I wanted to import got me the OLE error 80131124, which according to https://www.megos.ch/files/content/diverses/doserrors.txt means "Index %s not found", which isn't really helpful Is it really possible, that the list is empty? According to gacutils I have got a sh*tload of assemblies in the Global Assembly Cache This is Delphi 10.3.3
  11. dummzeuch

    spinlock primitives

    ... or simply assume a multi core system. When was the last time you saw a single core (Windows-) system in the wild? OK, a program could be restricted to a single core by the user or the OS, so there is that. And there are VMs which can also be configured to run on a single core even on a multi core system.
  12. COVID-19 got us all down a bit and even with the vaccines theoretically available now, the light at the end of the tunnel seems very far away. My own turn for a jab will probably not come before fall 2021, so I can only hope that summer will reduce the infection rates as much as it did last year, but the new mutants that spread around the world definitely aren’t good news. Maybe I can lighten up your mood a bit with a new GExperts release. There are a few bug fixes and an also a few new features in the new version, but nothing really exciting. read on in the blog post.
  13. dummzeuch

    spinlock primitives

    I'm writing my own spinlock to get a feel for what can be done. One of my programs shows some odd behavior when using a critical section so I tried to see whether this changes when switching to a spin lock. It seemed to work at first, but my last test failed miserably so I'm "going home" now. Quite possible, but since these require API calls, they have a significant overhead in the best case (no spinning required). I knew about Sleep(0) vs. Sleep(1), but wasn't that supposed to be changed in Windows Vista and later? (reading the second link) OK, apparently not. But since the threads in question are running with the same priority, Sleep(0) should work fine. Apart from that: the above code was just an example, how to prevent running a single CPU system at 100%.
  14. dummzeuch

    spinlock primitives

    You mean instead of Sleep()? I haven't thought much about that case yet. Using doTryLock it with sleep which gives a much higher throughput than doLock or a Critical Section in my tests on my computer. But I am not yet sure whether this makes any difference in a real world scenario. Apparently there the is the Pause instruction on Intel CPUs: https://stackoverflow.com/questions/4725676/how-does-x86-pause-instruction-work-in-spinlock-and-can-it-be-used-in-other-sc I'll have to look into it.
  15. dummzeuch

    spinlock primitives

    Yes, thats how a SpinLock is supposed to work, isn't it? That's why I added the doTryLock function which could be used like this: while not doTryLock(Lck) do Sleep(0);
  16. dummzeuch

    GExperts 1.3.18 experimental twm 2021-02-21 released

    Does anybody else have this compile error?
  17. dummzeuch

    GExperts 1.3.18 experimental twm 2021-02-21 released

    Hm, that's odd: I just checked out the sources to a new directory and run the build script. Compiled fine. (Bloody license server is acting up again, so I can't load it into the IDE right now.)
  18. dummzeuch

    GExperts 1.3.18 experimental twm 2021-02-21 released

    Oddly enough, the file is right there: In Directory Source\UsesExpert: (Maybe it doesn't really belong in this directory because it's used by a unit in framework) I'm not sure what causes the compile error, but I will investigate. Did you compile in the IDE or via the build script?
  19. dummzeuch

    GExperts 1.3.18 experimental twm 2021-02-21 released

    Not the genie, the GExpert 😉
  20. dummzeuch

    GExperts 1.3.18 experimental twm 2021-02-21 released

    Please no discussion about Covid here.
  21. dummzeuch

    Gexpert compile under Delphi 10.4

    I just committed a dproj file for Delphi 10.4 (GExpertsGrep.10-4.dproj) This works for me. The automatically converted Delphi 2007 dproj file didn't work for me either.
  22. Ouch! Wtf did they declare it public in TCustomEdit? Most not-yet-published properties of other components are declared protected. But there are exceptions there too: TCustomLabel.Caption is also public. Why? (Yes, I know, I won't get any definite answer here unless some Borland employee talked about it in the 1990s.)
  23. Does anybody know how to prevent the ExplicitTop/Left/Width/Height properties from being written to the DFM file? I never saw any use for them and always installed Andreas Hausladen's DDevExtensions which allows to remove them. But since Andy apparently doesn't have access to the latest Delphi version there is no DDevExtensions (and also no IDE Fix Pack) for Delphi 10.4(.1) and I would like to add that functionality to GExperts. I tried, but so far failed. Any hints?
  24. dummzeuch

    Gexpert compile under Delphi 10.4

    I always compile that tool with Delphi 2007. I currently can't test whether it compiles with Delphi 10.4 due a a connection problem with the license server. I have only seen that with Delphi 2007 before. It happens every time a Windows update deletes the files that the Delphi 2007 installer put into that directory. After I copied them back and everything compiled normally.
  25. dummzeuch

    remove ExplicitXxxx properties

    ... and other older posts in this topic.
×