[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

Thread synchronizing

Posted on 2004-04-29
4
Medium Priority
?
403 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

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

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

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…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Suggested Courses

650 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