AGB  ·  Datenschutz  ·  Impressum  







Anmelden
Nützliche Links
Registrieren
Zurück Delphi-PRAXiS Programmierung allgemein Programmieren allgemein Delphi TThread mit Queue und Events
Thema durchsuchen
Ansicht
Themen-Optionen

TThread mit Queue und Events

Ein Thema von AJ_Oldendorf · begonnen am 26. Mai 2025 · letzter Beitrag vom 28. Mai 2025
Antwort Antwort
Benutzerbild von Mavarik
Mavarik

Registriert seit: 9. Feb 2006
Ort: Stolberg (Rhld)
4.157 Beiträge
 
Delphi 10.3 Rio
 
#1

AW: TThread mit Queue und Events

  Alt 27. Mai 2025, 14:43
Hmmm, meinst Du damit, er SOLLTE besser kein Sleep einsetzen? .... oder er kann gar kein Sleep ausführen?
Natürlich geht ein Sleep, aber ich nutze doch einen Thread um etwas parallel oder schneller zu machen.
Daher macht für mich ein Sleep in einem Thread nie einen Sinn.


Wenn es rein um eine Verzögerung geht, sehe ich auch keinen Grund, das mit Events oder ähnlichem umzusetzen. Das Ergebnis ist das gleiche, ob ich auf ein Event eine bestimmte Zeit bis zum Timeout warte oder dies mit Sleep direkt mache.
Ob das das gleiche ist möchte ich (ungetestet) bezweifeln. Aber in diesem Beispiel nutzt man ja einen TEvent um keinerlei CPU Zyklen zu verschwenden. Immer warten und pollen macht halt überhaupt keinen Sinn, wenn ich auch auf einen Event in Best Case: ~1–10 µs (Mikrosekunden) reagieren kann.

Ich persönlich finde den zusätzlichen Code für z.B. ein Event nicht gerade gut für die Lesbarkeit, denn das Event hat ja selbst dann gar keine Funktion.
Doch genau das was er soll... Warten bis etwas neues in der Queue ist. (Oder Terminate)

Mavarik
  Mit Zitat antworten Zitat
Benutzerbild von jaenicke
jaenicke

Registriert seit: 10. Jun 2003
Ort: Berlin
9.990 Beiträge
 
Delphi 12 Athens
 
#2

AW: TThread mit Queue und Events

  Alt 27. Mai 2025, 14:51
Doch genau das was er soll... Warten bis etwas neues in der Queue ist. (Oder Terminate)
Ich habe ja geschrieben, dass das für den Fall passt.

Aber wer soll das Event auslösen, wenn ich z.B. einen Server pollen möchte, ob er neue Daten hat? Aber eben mit etwas Wartezeit dazwischen.

Es gibt auch andere Konstellationen als dass ein Thread zur Beschleunigung durch Parallelisierung dienen soll oder auf konkret abfragbare Events wartet.
Sebastian Jänicke
AppCentral
  Mit Zitat antworten Zitat
Kas Ob.

Registriert seit: 3. Sep 2023
436 Beiträge
 
#3

AW: TThread mit Queue und Events

  Alt Gestern, 09:03
Doch genau das was er soll... Warten bis etwas neues in der Queue ist. (Oder Terminate)
Aber wer soll das Event auslösen, wenn ich z.B. einen Server pollen möchte, ob er neue Daten hat? Aber eben mit etwas Wartezeit dazwischen.
I don't recall a single Windows IO operation that doesn't support both blocking and non-blocking, synchronous or asynchronous, they all fall in one way or other under overlapped, and they all have the possibility to attach an event to automatically triggered, as for the same example like a server then either
1) block on "recv" and skip the event altogether or
2) block on "select" to get the state of the socket and have the exact moment of/for receiving data, or
3) use WSAEventSelect and WSAAsyncSelect , these are powerful to combine with other complex or non-complex operation, events here become central notification for one or more threads.
4) IOCP and don't even wait manually, get the operation and process the data in place within the thread knowing there is other threads allowed to process other client...
5) ..
6) ..
there is many approaches and that only for handling sockets on server or client side, same goes for files ReadFile and ReadFileEx, they have differences and can combined in many different ways, if you prefer events then overlapped with supplied event is the way to go, work like charm with com and legacy communication ports, allowing you to utilize the maximum throughput being writing files to disk or sending data to hardware wire or a driver ...

The overlapped design and operation are powerful and efficient, the core of overlapped mechanism is low level kernel triggered events.

Es gibt auch andere Konstellationen als dass ein Thread zur Beschleunigung durch Parallelisierung dienen soll oder auf konkret abfragbare Events wartet.
Of course there is, there is always such needed design where time interval is needed at the exact point, in other words, time is essential for non performed operation or non triggered event, may be a timer, may be we want to control the time out for a socket, short one and dont want to depend on socket provider timeout..etc ,
other than that i see polling as waste of time and CPU cycle as as Mavarik, for fast and lazy or limited usage then yes, poll then execute then sleep for short time, but with servers with many clients and many threads, this is a waste.
Kas
  Mit Zitat antworten Zitat
Antwort Antwort


Forumregeln

Es ist dir nicht erlaubt, neue Themen zu verfassen.
Es ist dir nicht erlaubt, auf Beiträge zu antworten.
Es ist dir nicht erlaubt, Anhänge hochzuladen.
Es ist dir nicht erlaubt, deine Beiträge zu bearbeiten.

BB-Code ist an.
Smileys sind an.
[IMG] Code ist an.
HTML-Code ist aus.
Trackbacks are an
Pingbacks are an
Refbacks are aus

Gehe zu:

Impressum · AGB · Datenschutz · Nach oben
Alle Zeitangaben in WEZ +1. Es ist jetzt 11:37 Uhr.
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024-2025 by Thomas Breitkreuz