Solved

Preventing multiple events calling a running  thread

Posted on 1998-12-16
2
171 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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
How to debug For loops? 3 60
tvirtualstringtree freeze when load too manny images 10 79
Wincontrol not (correctly) drawn 15 47
enhance the following code 3 42
This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial

685 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