Keys - Thread-spezifische Daten

  • Threads rufen Routinen auf
  • Routinelokale Daten kommen und gehen
  • Alternativen
    • Routine Pointer auf Daten übergeben
    • globale Variablen
    • selbst hacken mit pthread_self
  • Bibliothek
    • hat interne Daten
    • umschreiben auf MT
    • API bleibt gleich
    • hat jetzt Threadspezifische interne Daten

Key

  • eine Art Pointer
  • wenn dieser Pointer von einem Thread verwendet wird, zeigt er jedes Mal auf die Threadeigenen Daten

Alternativen

  • open gibt connection ID zurück
    • recieve, send (id, ...)
    • API wechselt
    • Kapselung, Abstraktion?
  • Array auf Heap anlegen und mit pthread_self referenzieren
  • entweder hässlich oder rel. Aufwendig

Anwendungsbeispiele

  • Modul für Speicher oder File Management
  • Profiling Modul
  • Exception Manager
    • speichert Ort an den bei einer Exception gesprungen werden soll
  • Zufallszahlen Generator

Generell

  • Bibliotheken oder Routinen mit internem Zustand
  • Kontext soll nicht als Parameter übergeben werden
  • üblicherweise wird Kontext in single threaded Programmen als static declariert
  • bei nichtBibliotheken sind Keys nicht unbedingt vorteilhaft
    • globale Variablen
  • Key kann auch direkt per pthread_key_delete wieder gelöscht werden.

Post new comment

The content of this field is kept private and will not be shown publicly.
  • Use <fn>...</fn> to insert automatically numbered footnotes.
  • You can use the <go> tags just like the <a> for nicer urls.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • You can enable syntax highlighting of source code with the following tags: <code>, <blockcode>. Beside the tag style "<foo>" it is also possible to use "[foo]".
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.

More information about formatting options

CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.
Image CAPTCHA
Copy the characters (respecting upper/lower case) from the image.