git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH] MSVC: Windows-native implementation for subset of Pthreads API

From
Nicolas Pitre <nico@fluxnic.net>
Date
Nov 5, 2009, 02:10 UTC
Message-ID
<alpine.LFD.2.00.0911042039200.10340@xanadu.home>
In-Reply-To
<4AF214D5.6050202@gmail.com>
On Thu, 5 Nov 2009, Andrzej K. Haczewski wrote:
Show 11 quoted lines
> +static inline int pthread_cond_init(pthread_cond_t *cond, const void *unused)
> +{
> +	cond->waiters = 0;
> +
> +	InitializeCriticalSection(&cond->waiters_lock);
> +
> +	cond->sema = CreateSemaphore(NULL, 0, LONG_MAX, NULL);
> +	if (!cond->sema)
> +		return 0; /* POSIX do not allow pthread_cond_init to fail */
> +	return 0;
> +}

Please use die("CreateSemaphore() failed") in the failure case instead of returning success.

However, my pthread_cond_init man page says:
[[[
RETURN VALUE
       If successful, the pthread_cond_destroy() and pthread_cond_init() func-
       tions  shall  return zero; otherwise, an error number shall be returned
       to indicate the error.
       The [EBUSY] and [EINVAL] error checks, if implemented, shall act as  if
       they  were performed immediately at the beginning of processing for the
       function and caused an error return prior to modifying the state of the
       condition variable specified by cond.
ERRORS
       The pthread_cond_destroy() function may fail if:
       EBUSY  The implementation has detected an attempt to destroy the object
              referenced by cond while it is referenced  (for  example,  while
              being used in a pthread_cond_wait() or pthread_cond_timedwait())
              by another thread.
       EINVAL The value specified by cond is invalid.
       The pthread_cond_init() function shall fail if:
       EAGAIN The system lacked the necessary resources (other than memory) to
              initialize another condition variable.
       ENOMEM Insufficient memory exists to initialize the condition variable.
       The pthread_cond_init() function may fail if:
       EBUSY  The implementation has detected an attempt to  reinitialize  the
              object referenced by cond, a previously initialized, but not yet
              destroyed, condition variable.
       EINVAL The value specified by attr is invalid.
]]]

I'm not advocating that you implement detailed error codes as we don't really care about specific errors. This is just to disagree with the "POSIX do not allow pthread_cond_init to fail" assertion. In any case, using die() to keep it simple is certainly better than blindly returning 0 on failure. However you could simply return ENOMEM and use the die() in init_threaded_search() instead.

Nicolas
Previous: Nicolas PitreNext: Andrzej K. Haczewski
Message 51 of 62 in “Port of pthreads to Windows API threads”
  1. 0/1 Port of pthreads to Windows API threadsAndrzej K. Haczewski, Nov 3, 2009
  2. 1/1 MSVC: port pthread code to native Windows threadsAndrzej K. Haczewski, Nov 3, 2009
  3. Johannes SchindelinNov 3, 2009
  4. Joshua JensenNov 4, 2009
  5. Andrzej K. HaczewskiNov 4, 2009
  6. Johannes SixtNov 4, 2009
  7. Johannes SchindelinNov 4, 2009
  8. Andrzej K. HaczewskiNov 4, 2009
  9. Johannes SixtNov 4, 2009
  10. Michael WookeyNov 4, 2009
  11. Andrzej K. HaczewskiNov 4, 2009
  12. MSVC: port pthread code to native Windows threadsAndrzej K. Haczewski, Nov 4, 2009
  13. Erik Faye-LundNov 4, 2009
  14. Andrzej K. HaczewskiNov 4, 2009
  15. Paolo BonziniNov 4, 2009
  16. Paolo BonziniNov 4, 2009
  17. Johannes SixtNov 4, 2009
  18. Andrzej K. HaczewskiNov 4, 2009
  19. Johannes SixtNov 4, 2009
  20. Andrzej K. HaczewskiNov 4, 2009
  21. Daniel BarkalowNov 4, 2009
  22. Nicolas PitreNov 4, 2009
  23. Daniel BarkalowNov 4, 2009
  24. Nicolas PitreNov 5, 2009
  25. Dmitry PotapovNov 5, 2009
  26. Andrzej K. HaczewskiNov 4, 2009
  27. Erik Faye-LundNov 4, 2009
  28. Johannes SchindelinNov 4, 2009
  29. MSVC: Windows-native implementation for subset of Pthreads APIAndrzej K. Haczewski, Nov 4, 2009
  30. Nicolas PitreNov 4, 2009
  31. Andrzej K. HaczewskiNov 4, 2009
  32. pack-objects: move thread autodetection closer to relevant codeNicolas Pitre, Nov 4, 2009
  33. Junio C HamanoNov 6, 2009
  34. Erik Faye-LundNov 4, 2009
  35. Andrzej K. HaczewskiNov 4, 2009
  36. Nicolas PitreNov 5, 2009
  37. Andrzej K. HaczewskiNov 5, 2009
  38. Erik Faye-LundNov 5, 2009
  39. MSVC: Windows-native implementation for subset of Pthreads APIAndrzej K. Haczewski, Nov 5, 2009
  40. Johannes SixtNov 5, 2009
  41. Andrzej K. HaczewskiNov 5, 2009
  42. Nicolas PitreNov 5, 2009
  43. Andrzej K. HaczewskiNov 5, 2009
  44. Nicolas PitreNov 5, 2009
  45. Nicolas PitreNov 4, 2009
  46. MSVC: Windows-native implementation for subset of Pthreads APIAndrzej K. Haczewski, Nov 4, 2009
  47. MSVC: Windows-native implementation for subset of Pthreads APIAndrzej K. Haczewski, Nov 4, 2009
  48. Nicolas PitreNov 5, 2009
  49. Andrzej K. HaczewskiNov 5, 2009
  50. Nicolas PitreNov 5, 2009
  51. Nicolas PitreNov 5, 2009
  52. Andrzej K. HaczewskiNov 5, 2009
  53. Nicolas PitreNov 5, 2009
  54. Johannes SixtNov 5, 2009
  55. Junio C HamanoNov 4, 2009
  56. MSVC: Windows-native implementation for subset of Pthreads APIAndrzej K. Haczewski, Nov 5, 2009
  57. Johannes SixtNov 5, 2009
  58. Nicolas PitreNov 5, 2009
  59. Andrzej K. HaczewskiNov 5, 2009
  60. Nicolas PitreNov 5, 2009
  61. MSVC: Windows-native implementation for subset of Pthreads APIAndrzej K. Haczewski, Nov 6, 2009
  62. Johannes SixtNov 6, 2009

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.