Solved

Preventing multiple events calling a running  thread

Posted on 1998-12-16
2
172 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Working with hours 3 86
Adoquery sql  left join does not work 25 119
IdTCPClient and IdTCPServer exchanging data on desktops and not Android 11 196
Delphi, TImage, Png 2 53
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…
In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …

739 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