Jump to content

David Heffernan

Members
  • Content Count

    3536
  • Joined

  • Last visited

  • Days Won

    175

Posts posted by David Heffernan


  1. No. That's not what Invalidate does. It marks the paint box as invalid. And then when the message queue is next empty, a paint event gets synthesised. 

     

    The thing is, at some point you need to make the main thread wake up and do something. What's your plan for doing that? Perhaps what you want to do is note that an update is required with a flag and then check that on an update timer in the main thread. That would be a sensible approach if the frequency of updates from the threads was very high. 

     

    Bear in mind that in the OP you suggested sending a message from the worker thread to the main thread. Have you now decided that you don't want to do that? 


  2. 26 minutes ago, Jacek Laskowski said:

    Calling Queue from the thread is a bad idea here. There are several threads, each of them processes some data, and one visual control displays them. If each thread is forcing a refresh, it will be a heavy load. And if the light gets messages, even from a few threads, it will decide how to refresh itself.

    Dude, it was you that wanted to have the worker thread notify the main thread! That's literally what you asked in the OP.

     

    26 minutes ago, Jacek Laskowski said:

    How to handle the message the parent got? I don't know who the parent will be?

    Why would you opt to send a message to the parent? I only said that because you can't send a message to the paint box since it isn't windowed. Which is why Queue or Synchronize are cleaner.

     

    Ultimately, you need to call Invalidate on the paint box, from the main thread. And you need to decide what is going to trigger that to happen.  I gave you some examples, and of course there are other ways. But your have to make you own mind up.


  3. 6 hours ago, Vincent Parrett said:

    Or avoid Synchronize and send custom message to the control using PostMessage(control.handle,...) and call invalidate in the message handler. 

    Use TThread.Queue, not least because the paint box isn't windowed. 


  4. You never send a WM_PAINT message to a control. You invalidate in. For a plain Win32 control that means calling InvalidateRect. For a VCL control that means calling Invalidate. 

     

    You don't want to call that from a thread. Use Synchronize to execute code on the UI thread. 


  5. 6 hours ago, pyscripter said:

    Right now the quality portal is updated at a frenetic rate.  There was a very large number of fixes, I think more than in any other previous version, and I was quite pleased that quite a few of my reports have been resolved, some of the unexpectedly:

     

    System.Threading got some attention with the famous Cancel and Wait issue resolved.

     

    Issues I would like to see fixed now and consider critical are:

     

     

     

    On the plus side these can be readily fixed yourself for your programs. 

     

    I mean, I've been running with a patched RTL for years that fixes all the design flaws in handling of floating point control flags. 

     

    At least we have access to the RTL source code and so can apply fixes easily using code hooks. 


  6. Automating Word for document preparation is known to be somewhat brittle. More robust is to generate Word documents directly without invoking Word at all. There are good libraries for doing that. That's the point.

     

    If you are going to rely on Word for this then it pays to be very careful about the version that you use. Switching to Office 365 is simply asking for trouble. 


  7. You can't have read the documentation. Because you aren't calling ShutdownBlockReasonCreate. 

     

    I know that you want to solve this quickly. But that expectation is unrealistic. It will take you time to wade through this, try it out, read and understand example code, etc.

     

    For sure one of us could write you some examples but unless you understand it will you really be able to integrate it into your code? Just because you don't understand this now does not mean that you can't learn it. It just requires self belief and persistence. 


  8. It's astonishing that Emba's InterlockedCompareExchange128 returns a BOOL, i.e. a 4 byte boolean, LongBool. They are presumably trying to copy this one from MS https://docs.microsoft.com/en-us/windows/win32/api/winnt/nf-winnt-interlockedcompareexchange128 which is actually implemented as an intrinsic.

     

    But look at the MS function's return type.  Yup, it's BOOLEAN which is a single byte.  The Emba version should use Boolean rather than Bool as the return type.  It's a screw-up from top to bottom.

     

    Anyone might think that they just write this stuff and don't test it ......


  9. 6 minutes ago, Anders Melander said:

    I always start with registers and then refactor the code to use symbols to make it readable. I guess I should keep the register names in a comment.

    To me it is much cleaner to comment at the top of the routine which register each parameter travels in, and then stick to registers. That allows you to see teg register usage directly rather than having an extra level of indirection. 


  10. 7 minutes ago, Anders Melander said:

    Beware that this does not align memory allocated from the heap. For that you can use the following:

    
    {$ifdef CPUX64}
      SetMinimumBlockAlignment(mba16Byte);
    {$else CPUX64}
      SetMinimumBlockAlignment(mba8Byte);
    {$endif CPUX64}

     

    This works for me:

    
    function InterlockedCompareExchange128(Destination: Pointer; ExchangeHigh, ExchangeLow: Int64; ComparandResult: Pointer): Bool; stdcall;
    asm
          .NOFRAME
          .PUSHNV R10
          .PUSHNV RAX
          .PUSHNV RBX
          .PUSHNV RCX
          MOV   R10,Destination
          MOV   RBX,ExchangeLow
          MOV   RCX,ExchangeHigh
          MOV   RDX,[ComparandResult+8]
          MOV   RAX,[ComparandResult]
     LOCK CMPXCHG16B [R10]
          SETZ  AL
    end;

    The PUSHNV RBX is translated to push RBX + pop RBX. The others do nothing.

    You are restoring volatile registers there. That's wrong. Most egregious is where you restore rax which has the return value. 

     

    Ah, i read the bit where you say "the others do nothing". I guess the compiler knows they are volatile / used for param/return passing. I'd remove them all the same. 

     

    You really must stop using parameter names in asm because it obfuscates the fact they they live in registers, and which ones. 

×