Recent

Author Topic: can 2 event handlers be running simultaneously?  (Read 2124 times)

PaulRowntree

  • Full Member
  • ***
  • Posts: 132
    • Paul Rowntree
can 2 event handlers be running simultaneously?
« on: August 21, 2018, 03:02:23 am »
I am writing Win64/Win32 applications, without explicitly launching concurrent threads.  Can I be confident that there will never be more than 1 event handler actually running in my code at any instant, or is this a naive view of what is going on behind the scenes?
My specific case is a TTimer event handler that checks SimpleIPC to see if there is any incoming information, then fire off sub-handlers to read and deal with that information.   Could the OS invoke other event handlers while my SimpleIPC handlers are grinding away?
Thanks!
 
Paul Rowntree
- coding for instrument control, data acquisition & analysis, CNC systems

ASerge

  • Hero Member
  • *****
  • Posts: 2212
Re: can 2 event handlers be running simultaneously?
« Reply #1 on: August 21, 2018, 03:29:09 am »
If you use only the client and do not override the DefaultIPCClientClass, then in Windows TSimpleIPCClient uses windows messages - so only one thread works. So you can be confident.

PaulRowntree

  • Full Member
  • ***
  • Posts: 132
    • Paul Rowntree
Re: can 2 event handlers be running simultaneously?
« Reply #2 on: August 21, 2018, 04:06:18 am »
If you use only the client and do not override the DefaultIPCClientClass, then in Windows TSimpleIPCClient uses windows messages - so only one thread works. So you can be confident.
Thanks ASerge.  Actually, I was hoping to bundle a Client and a Server (ie put them in a wrapper, not subclassed) to make a bidirectional link.  The Client would be called by 'regular' routines, as a result of some action such as a button event or a timer event.  On the receiving end (the server), I wanted to install handlers that would get called when the server was polled to see if anything was in the pipe.
Does this start to shake my confidence?
Paul Rowntree
- coding for instrument control, data acquisition & analysis, CNC systems

Thaddy

  • Hero Member
  • *****
  • Posts: 14162
  • Probably until I exterminate Putin.
Re: can 2 event handlers be running simultaneously?
« Reply #3 on: August 21, 2018, 10:11:51 am »
Take a look at the pipes example that comes with Freepascal. That's an example of two way communication and it is cross-platform.
Specialize a type, not a var.

PaulRowntree

  • Full Member
  • ***
  • Posts: 132
    • Paul Rowntree
Re: can 2 event handlers be running simultaneously?
« Reply #4 on: August 21, 2018, 06:04:52 pm »
Take a look at the pipes example that comes with Freepascal. That's an example of two way communication and it is cross-platform.
Thanks Thaddy.  I can't see the example in FPC, but I have looked through some NamedPipes units (eg https://github.com/dezlov/NamedPipesFPC).  I am worried about connection errors and error trapping ... would pipes provide a more robust transport mechanism than simpleipc?
Cheers!
Paul Rowntree
- coding for instrument control, data acquisition & analysis, CNC systems

 

TinyPortal © 2005-2018