?
Solved

Thread synchronizing

Posted on 2004-04-29
4
Medium Priority
?
401 Views
Last Modified: 2010-04-05
This is a 'It works but I guess it can be done more clever' question:
A thread has to wait until a second thread has done its work. Actually I use a critical section:

Thread 1:
procedure TriggerSecondThreadAndWait;
begin
  TriggerThread_2;
  EnterSection;   // Suspend thread 1, I'm sure thread 2 already entered the section
  LeaveSection;
end;

Thread 2:
procedure DoWork;
begin
  EnterSection;   // To suspend thread 1
  DoSomeWork;
  LeaveSection;   // Resume thread 1
end;

Can I use a 'WaitForXYZ' instead. I've never done this before...
Thank you!
0
Comment
Question by:__alex
[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
  • 2
  • 2
4 Comments
 
LVL 7

Expert Comment

by:sftweng
ID: 10947352
0
 
LVL 2

Author Comment

by:__alex
ID: 10947625
???
TThread.WaitFor waits for termination of the thread. I don't want to terminate it.
0
 
LVL 7

Accepted Solution

by:
sftweng earned 1000 total points
ID: 10947699
Are you looking to use TEvent.WaitFor then?

Waits until another thread or process turns on the signal of the event object.

type TWaitResult = (wrSignaled, wrTimeout, wrAbandoned, wrError);
function WaitFor(Timeout: DWORD): TWaitResult;

Description

Call WaitFor to wait until the signal of the event object is turned on. If the signal is not set after TimeOut milliseconds, WaitFor returns anyway. WaitFor returns one of the following values:

Value      Meaning

wrSignaled      The signal of the event object was set.
wrTimeOut      The time specified by the TimeOut parameter elapsed without the signal being set.
wrAbandoned      The event object was destroyed before the TimeOut period elapsed.
wrError      An error occurred while waiting. Check the LastError property for an error code giving more information.
0
 
LVL 2

Author Comment

by:__alex
ID: 10947966
Yep, that's it, thank you!
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say 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

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
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…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
Suggested Courses

762 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