Solved

Preventing multiple events calling a running  thread

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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

706 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now