home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / std_unix / volume.27 / text0086.txt < prev    next >
Encoding:
Text File  |  1992-05-20  |  7.1 KB  |  189 lines

  1. Submitted-by: Erik_Brown@transarc.com
  2.  
  3.   Well, this list has been fairly quiet for a little while, so I
  4. thought I'd send my brief comments on the recent threading specs.  The
  5. format follows that given in Appendix B of the Draft 6 document.
  6.  
  7.   Please note that I do not speak as a representative of Transarc, but
  8. only on behalf of myself.
  9.  
  10. Erik Brown            eeb@transarc.com
  11. Transarc Corp            (412) 338-4426
  12. The Gulf Tower
  13. Pittsburgh, PA  15206
  14.  
  15. ------------------------------------------------------------------
  16.     Objections to Draft 6 of the POSIX 1003.4a Specification
  17.  
  18. ------------------------------------------------------------------
  19. Erik Brown        (412) 338-4426
  20. eeb@transarc.com    FAX: (412) 338-4404
  21. ------------------------------------------------------------------
  22. @ 4.4 o 1
  23.  
  24. PROBLEM
  25.  
  26.   The mutex attributes object may force the pthread_mutex_lock() and
  27. pthread_mutex_unlock() functions to do extra work when a mutex is
  28. acquired or released.  The Process-shared attribute especially may
  29. require extra checking for what should be a very low-level and fast
  30. operation.
  31.  
  32.   Providing an interface that allows a very fast low-level locking
  33. mechanism will encourage application developers to write code based
  34. solely on the standard.  With the current interface, vendors are
  35. likely to sacrifice portability in the interest of better performance
  36. by attempting to use hardware or OS-specific locking mechanisms where
  37. they are available.  This is especially true if an application does
  38. not interact with other processes and all threads run at the same
  39. priority, which is likely to be a common scenerio.
  40.  
  41. ACTION
  42.  
  43.   The pthread_mutexattr_t structure should be removed from the current
  44. mutex interface.
  45.  
  46.   The mutexattr functionality can be preserved by adding a new type of
  47. locking mechanism with its own attribute object that would allow the
  48. current functionality.  The synchronization protocols and priority
  49. ceilings in Section 6.3 would also be folded into this new mechanism.
  50.  
  51. ------------------------------------------------------------------
  52. @ 4.4 c 2
  53.  
  54. COMMENT
  55.  
  56.   It is unfortunate that pthread_mutex_lock() and
  57. pthread_mutex_unlock() are defined to return a value.  On a good RISC
  58. hardware platform with a test-and-set instruction, a lock can be
  59. performed in 2 or 3 instructions in user space, and an unlock in
  60. another 2 or 3 instructions.  Forcing these calls to return an integer
  61. value may add another 1 or 2 instruction to the implementation.
  62.  
  63.   In addition, the caller is forced to check the return code of these
  64. calls, adding yet another 4 or 5 instructions (to the lock/unlock
  65. pair).  In effect, the cost is almost doubled compared to the same
  66. calls implemented as void functions (assuming no errors).
  67.  
  68.   If users could be "trusted" not to call these routines incorrectly,
  69. or the working group were willing to allow a segmentation fault as the
  70. only error for an incorrectly called pthread_mutex_lock(), then it
  71. would be nice to see both of these calls as void functions.
  72.  
  73. ------------------------------------------------------------------
  74. @ 4.4 o 3
  75.  
  76. PROBLEM
  77.  
  78.   The definition of pthread_mutex_trylock() induces unnecessary
  79. overhead on the caller.  The user must check for -1, and then check
  80. for EBUSY to ensure that -1 was returned because the lock was already
  81. held.
  82.  
  83. ACTION
  84.  
  85.   Change the definition of this routine to return a boolean value, or
  86. -1 if a real error occurs.  That is, change lines 330 to 332 as
  87. follows:
  88.  
  89.     The function pthread_mutex_trylock() returns a positive
  90.     integer if the lock on the mutex object referenced by mutex is
  91.     acquired.  It returns 0 if the mutex is already locked.  If an
  92.     error occurs, it returns -1 and sets errno to indicate the
  93.     error.
  94.  
  95. ------------------------------------------------------------------
  96. @ 5.2 o 4
  97.  
  98. PROBLEM
  99.  
  100.   The pthread_getspecific() function in 5.2.2.1 is essentially a
  101. mechanism for providing special thread-specific memory.  This is
  102. likely to be heavily used by threaded applications, so performance of
  103. this function will be critical.  The performance of the current
  104. function is not optimal because the user must examine both the return
  105. code from the function and the value returned in the value parameter.
  106.  
  107. ACTION
  108.  
  109.   Change the routine to return the value of the given key, rather than
  110. accepting an address to store the value into.  If the key is invalid,
  111. 0 would be returned.  For instance, line 148 would change to be
  112.  
  113.     void *pthread_getspecific(pthread_key_t key);
  114.  
  115. ------------------------------------------------------------------
  116. @ 6.3 o 5
  117.  
  118. PROBLEM
  119.  
  120.   The mutex attributes object may force the pthread_mutex_lock() and
  121. pthread_mutex_unlock() functions to do extra work when a mutex is
  122. acquired or released.  Putting scheduling logic into the low-level
  123. synchronization primitive may be overkill for applications that run
  124. all of its threads with the same priority, or with mutexes that do not
  125. cross thread priority boundaries.
  126.  
  127.   Providing an interface that allows a very fast low-level locking
  128. mechanism will encourage application developers to write code based
  129. solely on the standard.  With the current interface, vendors are
  130. likely to sacrifice portability in the interest of better performance
  131. by attempting to use hardware or OS-specific locking mechanisms where
  132. they are available.  This is especially true if an application does
  133. not interact with other processes and all threads run at the same
  134. priority, which is likely to be a common scenerio.
  135.  
  136. ACTION
  137.  
  138.   While not applying to this section, the pthread_mutexattr_t
  139. structure should be removed from the interface.  A new type of locking
  140. mechanism can provide the synchronization protocols and priority
  141. ceilings in its own attribute object.  These functions should then be
  142. described in terms of this new interface.
  143.  
  144. ------------------------------------------------------------------
  145. @ 8.3 o 6
  146.  
  147. PROBLEM
  148.  
  149.   The list of async safe functions in 8.3.2 seems to be incomplete.
  150. In particular, the functions pthread_mutex_unlock() and pthread_self()
  151. should also be asyn safe.
  152.  
  153. ACTION
  154.  
  155.   Add these functions to the list given in the final paragraph.
  156.  
  157. ------------------------------------------------------------------
  158. @ 8.4 o 7
  159.  
  160. PROBLEM
  161.  
  162.   It seems reasonable that more than one thread in the same process
  163. might be interested in the same signal via the sigwait() function.
  164. Section 8.4.1.2 states that "exactly one of these threads shall return
  165. from sigwait() with the signal number."
  166.  
  167.   This seems unduly harsh.  For example, various libraries may wish to
  168. clean up from the receipt of a SIGINT, or check for a created child
  169. process (with a polling call to waitpid) when SIGCHLD is received.
  170. Allowing multiple libraries to perform these actions seems worthwhile
  171.  
  172. ACTION
  173.  
  174.   Change the second paragraph in Section 8.4.1.2 to read
  175.  
  176.     If more than one thread is using sigwait() to wait for the
  177.     same signal then all of these threads shall return from
  178.     sigwait() with the signal number.  No order can be assumed in
  179.     the delivery of the signals to the waiting threads.  Also, if
  180.     a thread exits the program after a return from sigwait(), then
  181.     other threads that were also waiting for the signal may not
  182.     actually receive it.
  183.  
  184. ------------------------------------------------------------------
  185.  
  186.  
  187. Volume-Number: Volume 27, Number 85
  188.  
  189.