AGB  ·  Datenschutz  ·  Impressum  







Anmelden
Nützliche Links
Registrieren
Thema durchsuchen
Ansicht
Themen-Optionen

Allgemeine Fragen zu Thread-Safety

Ein Thema von s.h.a.r.k · begonnen am 18. Jul 2011 · letzter Beitrag vom 18. Jul 2011
 
Benutzerbild von s.h.a.r.k
s.h.a.r.k

Registriert seit: 26. Mai 2004
3.159 Beiträge
 
#3

AW: Allgemeine Fragen zu Thread-Safety

  Alt 18. Jul 2011, 13:10
5. Nicht (unbedingt) threadsichere Methoden: Ich habe gerade einen Konstruktor geschrieben, der die Format-Methode nutzt. Ich weiß ja pauschal nicht, ob diese Methode threadsafe ist oder nicht. Daher hätte ich dann diesen Code ...
Delphi-Quellcode:
constructor TMyObject.Create(const AFormat: string; const Args: array of const);
begin
  inherited Create();
  FMessage := Format(AFormat, Args);
end;
... wie folgt umgeschrieben. Dieses Problem ist ja auch auf jede andere beliebige Methode "anwendbar" und nich auf Konstruktoren beschärnkt.
Delphi-Quellcode:
constructor TMyObject.Create(const AFormat: string; const Args: array of const);
begin
  inherited Create(); // Erzeugt eine CriticalSection, da von
                      // entsprechender Basisklasse abgeleitet
  Lock();
  try
    FMessage := Format(AFormat, Args);
  finally
    Unlock();
  end;
end;
»Remember, the future maintainer is the person you should be writing code for, not the compiler.« (Nick Hodges)
  Mit Zitat antworten Zitat
 


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 21:51 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