Solved

Thread synchronizing

Posted on 2004-04-29
4
391 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
  • 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 250 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

932 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now