Thanks for the review, Kirill!

Yeah, that's an important issue to consider. We could work around the problem 
by using InitializeCriticalSectionAndSpinCount (0x80000000). The API was 
introduced in Windows 2000, which is the first OS release that delays 
allocation of CRITICAL_SECTION events. That way only initialization can throw, 
but that happens when the library is loaded.

If you think it's simpler, we can opt for

union{
  SRWLOCK srw_lock;
  pthread_mutex_t mutex;
};

And use srw_lock if running on Vista or later. That can also help with 
contention since a few operations only need read access.

Best Regards,
Luca
________________________________
Da: Kirill Makurin <[email protected]>
Inviato: lunedì 28 settembre 2026 13:56
A: [email protected] 
<[email protected]>
Oggetto: Re: [Mingw-w64-public] [PATCH 5/6] winpthreads: Rework pthread_once 
implementation

Luca Bacci <[email protected]> wrote:

> +static struct {
> +  winpthreads_table_t table;
> +  CRITICAL_SECTION lock;
> +} downlevel;

I want to remove any use of `CRITICAL_SECTION` from winpthreads. On pre-Vista, 
`InitializeCriticalSection` may raise `STATUS_NO_MEMORY ` exception under low 
memory conditions.

Please consider using `pthread_spinlock_t` (same as error checking stalled 
mutex) or `pthread_mutex_t` instead; corresponding `pthread_*_init` function 
simply fails with `ENOMEM` or `EAGAIN` in such case.

- Kirill Makurin

_______________________________________________
Mingw-w64-public mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/mingw-w64-public

_______________________________________________
Mingw-w64-public mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/mingw-w64-public

Reply via email to