Solved

Thread synchronizing

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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

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…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
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…

705 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

20 Experts available now in Live!

Get 1:1 Help Now