Bibliotheksaufrufe & Fehler

Pthread Bibliotheksaufrufe geben bei Erfolg Null und ansonsten einen Fehlercode zurück, die Fehlercodes sind in errno.h definiert.

  1. #include <errno.h>
  2. #include <stdio.h>
  3. ...
  4. if (rtn = pthread_create(...)) {
  5.      /* Fehler ! */
  6.      fprintf(stderr, "Fehler: pthread_create, ");
  7.      if (rtn == EAGAIN)
  8.           fprintf(stderr, "Ressourcen reichen nicht\n");
  9.      else if (rtn == EINVAL)
  10.           fprintf(stderr, "Ungültige Argumente\n");
  11.      exit(1);
  12. }
  13. /* kein Fehler! */
  14. ...

alternativ kann der Klartext des Fehlers ausgegeben werden, wenn die Funktionalität zur Verfügung steht

  1. #include <string.h>
  2. #include <stdio.h>
  3. ...
  4. if (rtn = pthread_create(...)) {
  5.      fprintf(stderr, "Fehler: pthread_create, %s\n", strerror(rtn));
  6.      exit(1);
  7. }
  8. /* kein Fehler! */
  9. ...
  10. /* oder alternativ */
  11. if (rtn = pthread_create(...)) {
  12.      perror("Fehler aufgetreten: ");
  13.      exit(1);
  14. }

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.