Solved

Preventing multiple events calling a running  thread

Posted on 1998-12-16
2
170 Views
Last Modified: 2010-04-04
I am designing a server application using TCP/IP (TServerSocket).  An event is generated each time a request is recieved.  I have a que attached to one thread, when a message is added to the Que the que needs to call the thread if is not already running.  How do I do this without using flags (serverbusy true/false) and ensure that the event ends while the thread is running?.    
0
Comment
Question by:RobMartin
2 Comments
 

Author Comment

by:RobMartin
ID: 1351395
This problem seems similar to that an OS faces when handling multiple programs attempting to access one resource.  How does the OS block the request if active and then notif the app when it becomes free.
0
 
LVL 12

Accepted Solution

by:
rwilson032697 earned 100 total points
ID: 1351396
If you want to serialise access by these events to the thread then use critical sections (eg:EnterCriticalSection et al).

If you just want the event to abort if the thread is running you can do this a number of ways eg:

1. Checking the existence of the thread object if you create one when you need it.
2. By checking the suspended state of the thread if it suspends itself when it is dones

eg: if the thread suspends itself when it is done you can do this:

if ProcessorThread.Suspended then
  begin
    // Set some properties of the thread
   ...
   // activate thread again
  ProcessorThread.Suspended := false;
  end
else
  // abort processing this event.


Cheers,

Raymond.
0

Featured Post

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Delphi: how to send PJL commands to printer 3 108
Delphi 2 69
Reconfigure Delphi Install? 2 60
can't find the executable in Simulator 1 100
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

856 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question