Solved

Waiting On A Semiphore (semifore??)

Posted on 2000-04-10
5
198 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
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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

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 Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.

786 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