Delphi-PRAXiS

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   GUI-Design mit VCL / FireMonkey / Common Controls (https://www.delphipraxis.net/18-gui-design-mit-vcl-firemonkey-common-controls/)
-   -   Delphi Threads synchronisieren (https://www.delphipraxis.net/88680-threads-synchronisieren.html)

DelphiManiac 19. Mär 2007 12:06


Threads synchronisieren
 
Hallo,

ich habe mal wieder eine Frage bezüglich Threads:

ich nutze zurzeit 2 Threads
--> Main Thread der u.a. die GUI bedient
--> Nebenläufiger Thread (der bestimmte Kommunikationsanforderungen bearbeitet)

Meine Frage ist nun, kann ich mit einem Event vom Typ TEvent, welches ich im Thread als public anlege in
meinem Hauptthread darauf warten? Ist dieses threadsafe? Oder müsste ich das irgendwie noch absichern?

habe es zurzeit folgendermaßen:
Warten im Hauptthread
Delphi-Quellcode:
ergebnis:=aCyclicDataThread.fStoppEvent.WaitFor(2000);
    case ergebnis of
      wrSignaled: ;
      wrTimeout: ShowMessage('TimeOut') ;
      wrAbandoned: ;
      wrError: ;
    end;
    aCyclicDataThread.fStoppEvent.ResetEvent;
Im 2. Thread wird das Event gesetzt:
Delphi-Quellcode:
    try
      while fShouldStopp do
      begin
        fIsStopped:=true;
        fStoppEvent.SetEvent;
        fWoBinIch:=6;
        Sleep(100);
        if Self.Terminated then exit;
//        if Application.terminated then exit;
      end;
    finally
      fIsStopped:=true;
    end;
Danke euch!!

DelphiManiac 20. Mär 2007 11:28

Re: Threads synchronisieren
 
Kann mir niemand sagen ob das so erlaubt ist?

Danke schonmal im Vorraus..


Alle Zeitangaben in WEZ +1. Es ist jetzt 23:09 Uhr.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz