BUGS 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. ----------
  2. Known bugs
  3. ----------
  4. 1. Not strictly a bug, more of a gotcha.
  5. Under MS VC++ (only tested with version 6.0), a term_func
  6. set via the standard C++ set_terminate() function causes the
  7. application to abort.
  8. Notes from the MSVC++ manual:
  9. 1) A term_func() should call exit(), otherwise
  10. abort() will be called on return to the caller.
  11. A call to abort() raises SIGABRT and the default signal handler
  12. for all signals terminates the calling program with
  13. exit code 3.
  14. 2) A term_func() must not throw an exception. Therefore
  15. term_func() should not call pthread_exit(), which
  16. works by throwing an exception (pthreadVCE or pthreadVSE)
  17. or by calling longjmp (pthreadVC).
  18. Workaround: avoid using pthread_exit() in C++ applications. Exit
  19. threads by dropping through the end of the thread routine.
  20. 2. Cancellation problems in C++ builds
  21. - Milan Gardian
  22. [Note: It's not clear if this problem isn't simply due to the context
  23. switch in pthread_cancel() which occurs unless the QueueUserAPCEx
  24. library and driver are installed and used. Just like setjmp/longjmp,
  25. this is probably not going to work well in C++. In any case, unless for
  26. some very unusual reason you really must use the C++ build then please
  27. use the C build pthreadVC2.dll or pthreadGC2.dll, i.e. for C++
  28. applications.]
  29. This is suspected to be a compiler bug in VC6.0, and also seen in
  30. VC7.0 and VS .NET 2003. The GNU C++ compiler does not have a problem
  31. with this, and it has been reported that the Intel C++ 8.1 compiler
  32. and Visual C++ 2005 Express Edition Beta2 pass tests\semaphore4.c
  33. (which exposes the bug).
  34. Workaround [rpj - 2 Feb 2002]
  35. -----------------------------
  36. [Please note: this workaround did not solve a similar problem in
  37. snapshot-2004-11-03 or later, even though similar symptoms were seen.
  38. tests\semaphore4.c fails in that snapshot for the VCE version of the
  39. DLL.]
  40. The problem disappears when /Ob0 is used, i.e. /O2 /Ob0 works OK,
  41. but if you want to use inlining optimisation you can be much more
  42. specific about where it's switched off and on by using a pragma.
  43. So the inlining optimisation is interfering with the way that cleanup
  44. handlers are run. It appears to relate to auto-inlining of class methods
  45. since this is the only auto inlining that is performed at /O1 optimisation
  46. (functions with the "inline" qualifier are also inlined, but the problem
  47. doesn't appear to involve any such functions in the library or testsuite).
  48. In order to confirm the inlining culprit, the following use of pragmas
  49. eliminate the problem but I don't know how to make it transparent, putting
  50. it in, say, pthread.h where pthread_cleanup_push defined as a macro.
  51. #pragma inline_depth(0)
  52. pthread_cleanup_push(handlerFunc, (void *) &arg);
  53. /* ... */
  54. pthread_cleanup_pop(0);
  55. #pragma inline_depth()
  56. Note the empty () pragma value after the pop macro. This resets depth to the
  57. default. Or you can specify a non-zero depth here.
  58. The pragma is also needed (and now used) within the library itself wherever
  59. cleanup handlers are used (condvar.c and rwlock.c).
  60. Use of these pragmas allows compiler optimisations /O1 and /O2 to be
  61. used for either or both the library and applications.
  62. Experimenting further, I found that wrapping the actual cleanup handler
  63. function with #pragma auto_inline(off|on) does NOT work.
  64. MSVC6.0 doesn't appear to support the C99 standard's _Pragma directive,
  65. however, later versions may. This form is embeddable inside #define
  66. macros, which would be ideal because it would mean that it could be added
  67. to the push/pop macro definitions in pthread.h and hidden from the
  68. application programmer.
  69. [/rpj]
  70. Original problem description
  71. ----------------------------
  72. The cancellation (actually, cleanup-after-cancel) tests fail when using VC
  73. (professional) optimisation switches (/O1 or /O2) in pthreads library. I
  74. have not investigated which concrete optimisation technique causes this
  75. problem (/Og, /Oi, /Ot, /Oy, /Ob1, /Gs, /Gf, /Gy, etc.), but here is a
  76. summary of builds and corresponding failures:
  77. * pthreads VSE (optimised tests): OK
  78. * pthreads VCE (optimised tests): Failed "cleanup1" test (runtime)
  79. * pthreads VSE (DLL in CRT, optimised tests): OK
  80. * pthreads VCE (DLL in CRT, optimised tests): Failed "cleanup1" test
  81. (runtime)
  82. Please note that while in VSE version of the pthreads library the
  83. optimisation does not really have any impact on the tests (they pass OK), in
  84. VCE version addition of optimisation (/O2 in this case) causes the tests to
  85. fail uniformly - either in "cleanup0" or "cleanup1" test cases.
  86. Please note that all the tests above use default pthreads DLL (no
  87. optimisations, linked with either static or DLL CRT, based on test type).
  88. Therefore the problem lies not within the pthreads DLL but within the
  89. compiled client code (the application using pthreads -> involvement of
  90. "pthread.h").
  91. I think the message of this section is that usage of VCE version of pthreads
  92. in applications relying on cancellation/cleanup AND using optimisations for
  93. creation of production code is highly unreliable for the current version of
  94. the pthreads library.
  95. 3. The Borland Builder 5.5 version of the library produces memory read exceptions
  96. in some tests.
  97. 4. pthread_barrier_wait() can deadlock if the number of potential calling
  98. threads for a particular barrier is greater than the barrier count parameter
  99. given to pthread_barrier_init() for that barrier.
  100. This is due to the very lightweight implementation of pthread-win32 barriers.
  101. To cope with more than "count" possible waiters, barriers must effectively
  102. implement all the same safeguards as condition variables, making them much
  103. "heavier" than at present.
  104. The workaround is to ensure that no more than "count" threads attempt to wait
  105. at the barrier.
  106. 5. Canceling a thread blocked on pthread_once appears not to work in the MSVC++
  107. version of the library "pthreadVCE.dll". The test case "once3.c" hangs. I have no
  108. clues on this at present. All other versions pass this test ok - pthreadsVC.dll,
  109. pthreadsVSE.dll, pthreadsGC.dll and pthreadsGCE.dll.