Solved

Waiting On A Semiphore (semifore??)

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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Delphi XE10, MySQL Query 4 164
Intraweb download file link ? 1 153
how to change, disabled button color FMX ? 1 39
Slow Restore if incremental backups using RDiff.exe 4 28
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…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

765 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