Solved

Waiting On A Semiphore (semifore??)

Posted on 2000-04-10
5
211 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
[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
5 Comments
 

Expert Comment

by:sarc
ID: 2699471
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
ID: 2699478
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
ID: 2699703
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
ID: 2700812
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
ID: 2701658
Yup :-)
0

Featured Post

Independent Software Vendors: 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

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…
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…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

738 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