Solved

Waiting On A Semiphore (semifore??)

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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

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…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
Suggested Courses
Course of the Month4 days, 3 hours left to enroll

630 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