summaryrefslogtreecommitdiff
path: root/tests/libtest
diff options
context:
space:
mode:
authorMarc Hoersken <info@marc-hoersken.de>2022-10-12 00:21:23 +0200
committerMarc Hoersken <info@marc-hoersken.de>2022-10-19 11:59:00 +0200
commit81094cb49256dec3bdbe94052f8542b15d54e4a1 (patch)
tree7d9355cd5ebacd1dc920a6be953512df0b8d00b2 /tests/libtest
parent3f5a7975a509c6527ecc4f34e3a2a290354dab3e (diff)
downloadcurl-81094cb49256dec3bdbe94052f8542b15d54e4a1.tar.gz
tests: avoid CreateThread if _beginthreadex is available
CreateThread is not threadsafe if mixed with CRT calls. _beginthreadex on the other hand can be mixed with CRT. Reviewed-by: Marcel Raad Closes #9705
Diffstat (limited to 'tests/libtest')
-rw-r--r--tests/libtest/lib3026.c24
1 files changed, 20 insertions, 4 deletions
diff --git a/tests/libtest/lib3026.c b/tests/libtest/lib3026.c
index 33a2b56a5..8ad7e9490 100644
--- a/tests/libtest/lib3026.c
+++ b/tests/libtest/lib3026.c
@@ -29,7 +29,12 @@
#define NUM_THREADS 100
#ifdef WIN32
+#ifdef _WIN32_WCE
static DWORD WINAPI run_thread(LPVOID ptr)
+#else
+#include <process.h>
+static unsigned int WINAPI run_thread(void *ptr)
+#endif
{
CURLcode *result = ptr;
@@ -42,8 +47,15 @@ static DWORD WINAPI run_thread(LPVOID ptr)
int test(char *URL)
{
+#ifdef _WIN32_WCE
+ typedef HANDLE curl_win_thread_handle_t;
+#elif defined(__MINGW32__) && !defined(__MINGW64_VERSION_MAJOR)
+ typedef unsigned long curl_win_thread_handle_t;
+#else
+ typedef uintptr_t curl_win_thread_handle_t;
+#endif
CURLcode results[NUM_THREADS];
- HANDLE ths[NUM_THREADS];
+ curl_win_thread_handle_t ths[NUM_THREADS];
unsigned tid_count = NUM_THREADS, i;
int test_failure = 0;
curl_version_info_data *ver;
@@ -58,9 +70,13 @@ int test(char *URL)
}
for(i = 0; i < tid_count; i++) {
- HANDLE th;
+ curl_win_thread_handle_t th;
results[i] = CURL_LAST; /* initialize with invalid value */
+#ifdef _WIN32_WCE
th = CreateThread(NULL, 0, run_thread, &results[i], 0, NULL);
+#else
+ th = _beginthreadex(NULL, 0, run_thread, &results[i], 0, NULL);
+#endif
if(!th) {
fprintf(stderr, "%s:%d Couldn't create thread, errno %d\n",
__FILE__, __LINE__, GetLastError());
@@ -73,8 +89,8 @@ int test(char *URL)
cleanup:
for(i = 0; i < tid_count; i++) {
- WaitForSingleObject(ths[i], INFINITE);
- CloseHandle(ths[i]);
+ WaitForSingleObject((HANDLE)ths[i], INFINITE);
+ CloseHandle((HANDLE)ths[i]);
if(results[i] != CURLE_OK) {
fprintf(stderr, "%s:%d thread[%u]: curl_global_init() failed,"
"with code %d (%s)\n", __FILE__, __LINE__,