Solved

Thread synchronizing

Posted on 2004-04-29
4
393 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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

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…
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…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

813 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

12 Experts available now in Live!

Get 1:1 Help Now