Solved

Waiting On A Semiphore (semifore??)

Posted on 2000-04-10
5
194 Views
Last Modified: 2010-05-18
It's a pretty simple question...

How do I wait on a semiphore in DELPHI?
0
Comment
Question by:kalliopi
5 Comments
 

Expert Comment

by:sarc
Comment Utility
I think, you mean a semAphore?

This might be easy - or difficult. To answer this question we need more information....

For example a "file semaphore":

One program writes a file (can be empty, but can contain information, too) when starting a specific operation. All other programs now know that this operation is in progress (and they are not allowed to interfere at the moment). If the program is ready, the file is deletet.

This is only ONE example of thousands for the use of semaphores. The range of usage goes from Database programming to the windows multitasking core itself and from files to registers...

On what kind of semaphore (I still think, you mean this) do you want to wait???


greetz
Carsten
0
 
LVL 9

Expert Comment

by:ITugay
Comment Utility
The semifore (traffic light) may be simple boolean variable. When you waiting for it changed you need to give an ability to application to continue its work.

------
var Semifore : boolean;

procedure WaitForSemifore;
begin
    while not Semiphore
      do Application.ProcessMessages; // or Application.HandleMessage
end;

----
Igor.
0
 
LVL 10

Accepted Solution

by:
Lischke earned 50 total points
Comment Utility
kalliopi,

if you refer to standard semaphores as they are implemented in Win32 then your task is indeed very easy. Once you  created/opended the semaphore with CreateSemaphore (or OpenSemaphore) you can use the returned handle to passed it to WaitForSingleObject like:

case WaitForSingleObject(SemaphoreHandle, Timeout {or INFINITE}) of
  WAIT_OBJECT_0:
    // Semaphore is now signalled, which means its value is > 0
  WAIT_TIMEOUT:
    // the timeout value (if given) has been elapsed without the semaphore being signalled (value is still zero)
end;

Ciao, Mike
0
 
LVL 6

Author Comment

by:kalliopi
Comment Utility
Mike,

Thanx.  That was exactly what I was looking for.  I've had to use "while true Application.ProcessMessages and it's just killing my CPU time.  Thanx much.  That's great.
0
 
LVL 10

Expert Comment

by:Lischke
Comment Utility
Yup :-)
0

Featured Post

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

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…
Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

772 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

10 Experts available now in Live!

Get 1:1 Help Now