asyn-thrdd: manage DEFERRED and locks better

- cancel thread waits until thread start is at least 5ms in the past
  to give it some time to get its cancellation setup in place
- cancel thread without holding the mutex. It's supposed to be an
  async operation, but better be safe
- set DEFERRED cancel state explicitly, should be default in a pthread,
  but better be safe

Closes #18350
This commit is contained in:
Stefan Eissing 2025-08-22 15:24:04 +02:00 committed by Daniel Stenberg
parent f5ee566dbc
commit a8d20cd223
No known key found for this signature in database
GPG key ID: 5CC908FDB71E12C2
3 changed files with 58 additions and 55 deletions

View file

@ -75,11 +75,14 @@ int Curl_thread_cancel(curl_thread_t *hnd);
pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL)
#define Curl_thread_disable_cancel() \
pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, NULL)
#define Curl_thread_cancel_deferred() \
pthread_setcanceltype(PTHREAD_CANCEL_DEFERRED, NULL)
#else
#define Curl_thread_push_cleanup(a,b) ((void)a,(void)b)
#define Curl_thread_pop_cleanup() Curl_nop_stmt
#define Curl_thread_enable_cancel() Curl_nop_stmt
#define Curl_thread_disable_cancel() Curl_nop_stmt
#define Curl_thread_cancel_deferred() Curl_nop_stmt
#endif
#endif /* USE_THREADS_POSIX || USE_THREADS_WIN32 */