Beendigung von Threads - Cancellation

Warum?

  • Ressourcen zurückholen, wenn Thread nicht mehr gebraucht wird
    • z.B. Parallele Suche in DB
  • Cancellability State : J/N
  • Cancellability Type : asynchron/verzögert (deferred)
  • Warum nicht? Probleme
    • Daten Konsistenz -> zurücksetzen
    • Locks -> freigeben
  • Thread sollte nur an sicheren Punkten "cancellable" sein
  • Zu jedem Thread gehört ein "Cleanup Stack"

Cancellation Typen und Zustände

  • Thread setzt seine Cancellability selbst
  • Wechseln möglich und sinnvoll
  • Cancellability kann nur dynamisch zur Laufzeit gesetzt werden
  • Default: enabled, deferred cancellation
  • verzögerte Cancellation
    • Thread muss zuerst einen Cancel Point erreichen

Cancellation Points

  • State: enabled, Type: deferred
  • Automatic Cancellation Points
    • pthread_cond_wait
    • pthread_cond_timedwait
    • pthread_join
    • sigwait
    • (blockierende Aufrufe)
  • Vom Programmierer bestimmte Cancellation Points
    • pthread_testcancel
    • am besten vor CPU intensiven Arbeiten
  • Cancellation Points bei System und Library Aufrufen
  • Achtung: wenn CANCEL_ASYNC
    • Cancellation auch während
      • System und Bibliotheksaufrufen!
      • wenn Bibliothek nicht async-cancel sicher ist, vorher CANCEL_ASYNC ausschalten
  • Achtung: automatische Cancel Points, können das Konzept durcheinander bringen
    • wenn Code Abschnitte davon abhängen, keinen Cancelpoint zu haben, sollte dies explizit dokumentiert werden (/* ... */)
    • blockierende Aufrufe -> Cancel Point
    • System oder Bibliotheken können auch Cancel Points enthalten!

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.