Project homepage Mailing List  Warmcat.com  API Docs  Github Mirror 
{"schema":"libjg2-1", "vpath":"/git/", "avatar":"/git/avatar/", "alang":"", "gen_ut":1750650622, "reponame":"libwebsockets", "desc":"libwebsockets lightweight C networking library", "owner": { "name": "Andy Green", "email": "andy@warmcat.com", "md5": "c50933ca2aa61e0fe2c43d46bb6b59cb" },"url":"https://libwebsockets.org/repo/libwebsockets", "f":3, "items": [ {"schema":"libjg2-1", "cid":"06a93395ad8f6075151bbe79e847a8df", "commit": {"type":"commit", "time": 1586264721, "time_ofs": 60, "oid_tree": { "oid": "e5347c33481159b2e8e6e8a09835e3c95f45e9ef", "alias": []}, "oid":{ "oid": "d3308df40fcff457f23ed16d2485eb581a24fe18", "alias": []}, "msg": "windows: pthreads", "sig_commit": { "git_time": { "time": 1586264721, "offset": 60 }, "name": "Andy Green", "email": "andy@warmcat.com", "md5": "c50933ca2aa61e0fe2c43d46bb6b59cb" }, "sig_author": { "git_time": { "time": 1586264721, "offset": 60 }, "name": "Andy Green", "email": "andy@warmcat.com", "md5": "c50933ca2aa61e0fe2c43d46bb6b59cb" }}, "body": "windows: pthreads\n\nAdd support for external pthreads lib on windows and some docs about how to do.\n\nIt can build with LWS_WITH_THREADPOOL and LWS_WITH_MINIMAL_EXAMPLES including the\npthreads-dependent ones without warnings or errors on windows platform as well with this.\n\npthreads_t can be anything, including a struct - not a pointer-to-a-struct\nbut the struct itself. These can't be cast to a void * for printing as they can\non linux, where the base type is a pointer.\n\nLet's fix all the usage of those to determine their own thread index in terms\nof the meaning to the program rather than as a tid." , "diff": "diff --git a/CMakeLists.txt b/CMakeLists.txt\nindex 5d09379..3f9bc52 100644\n--- a/CMakeLists.txt\n+++ b/CMakeLists.txt\n@@ -497,7 +497,6 @@ endif()\n \n if (WIN32)\n set(LWS_MAX_SMP 1)\n-set(LWS_WITH_THREADPOOL 0)\n endif()\n \n if (LWS_WITHOUT_SERVER)\n@@ -592,6 +591,10 @@ set(LWS_GLIB_INCLUDE_DIRS CACHE PATH \u0022Path to the glib include directory\u0022)\n set(LWS_GLIB_LIBRARIES CACHE PATH \u0022Path to the glib library\u0022)\n set(LWS_LIBMOUNT_INCLUDE_DIRS CACHE PATH \u0022Path to the libmount include directory\u0022)\n set(LWS_LIBMOUNT_LIBRARIES CACHE PATH \u0022Path to the libmount library\u0022)\n+# on unix, these are in the toolchain. On win32 you have to put them somewhere\n+# yourself and point to them here\n+set(LWS_EXT_PTHREAD_INCLUDE_DIR CACHE PATH \u0022Path to an external pthreads include directory\u0022)\n+set(LWS_EXT_PTHREAD_LIBRARIES CACHE PATH \u0022Path to an external pthreads library\u0022)\n \n \n if (NOT LWS_WITH_SSL)\n@@ -911,6 +914,14 @@ if (NOT LWS_HAVE_GETIFADDRS)\n \tset(LWS_BUILTIN_GETIFADDRS 1)\n endif()\n \n+if (LWS_EXT_PTHREAD_INCLUDE_DIR)\n+\tset(CMAKE_REQUIRED_INCLUDES ${CMAKE_REQUIRED_INCLUDES};${LWS_EXT_PTHREAD_INCLUDE_DIR})\n+\tinclude_directories(${LWS_EXT_PTHREAD_INCLUDE_DIR})\n+\n+\tlist(APPEND LIB_LIST ${LWS_EXT_PTHREAD_LIBRARIES})\n+\tset(CMAKE_REQUIRED_FLAGS ${CMAKE_REQUIRED_FLAGS} \u0022 -DHAVE_STRUCT_TIMESPEC\u003d1\u0022)\n+endif()\n+\n CHECK_INCLUDE_FILE(dlfcn.h LWS_HAVE_DLFCN_H)\n CHECK_INCLUDE_FILE(fcntl.h LWS_HAVE_FCNTL_H)\n CHECK_INCLUDE_FILE(in6addr.h LWS_HAVE_IN6ADDR_H)\n@@ -1015,9 +1026,9 @@ CHECK_C_SOURCE_COMPILES(\u0022#include \u003cstdint.h\u003e\n \n if (LWS_HAVE_PTHREAD_H)\n \tif ((CMAKE_C_COMPILER_ID MATCHES \u0022Clang\u0022) OR (CMAKE_CXX_COMPILER_ID MATCHES \u0022Clang\u0022))\n-\t\tset(CMAKE_REQUIRED_FLAGS \u0022-pthread -Wno-error\u003dunused-command-line-argument\u0022)\n+\t\tset(CMAKE_REQUIRED_FLAGS ${CMAKE_REQUIRED_FLAGS} \u0022-pthread -Wno-error\u003dunused-command-line-argument\u0022)\n \telse()\n-\t\tset(CMAKE_REQUIRED_FLAGS \u0022-pthread\u0022)\n+\t\tset(CMAKE_REQUIRED_FLAGS ${CMAKE_REQUIRED_FLAGS} \u0022-pthread\u0022)\n \tendif()\n \n \tCHECK_C_SOURCE_COMPILES(\u0022#define _GNU_SOURCE\n@@ -1103,8 +1114,6 @@ if (LWS_WITH_FSMOUNT AND ${CMAKE_SYSTEM_NAME} STREQUAL \u0022Linux\u0022)\n \tlist(APPEND SOURCES lib/misc/fsmount.c)\n endif()\n \n-\n-\n if (LWS_WITH_FILE_OPS)\n \tlist(APPEND SOURCES lib/core/vfs.c)\n endif()\n@@ -1250,7 +1259,7 @@ if (LWS_ROLE_MQTT AND LWS_WITH_CLIENT)\n )\n endif()\n \n-if (LWS_WITH_THREADPOOL AND UNIX AND LWS_HAVE_PTHREAD_H)\n+if (LWS_WITH_THREADPOOL AND LWS_HAVE_PTHREAD_H)\n \tlist(APPEND SOURCES lib/misc/threadpool/threadpool.c)\n endif()\n \n@@ -1796,6 +1805,7 @@ source_group(\u0022Resources\u0022 FILES ${RESOURCES})\n #\n set(LWS_LIBRARIES)\n \n+\n if (LWS_WITH_STATIC)\n if (LWS_STATIC_PIC)\n set(CMAKE_POSITION_INDEPENDENT_CODE ON)\n@@ -1896,6 +1906,9 @@ set(LIB_LIST)\n #\n # Find libraries.\n #\n+if (LWS_EXT_PTHREAD_INCLUDE_DIR)\n+\tlist(APPEND LIB_LIST ${LWS_EXT_PTHREAD_LIBRARIES})\n+endif()\n \n #\n # ZLIB (needed for deflate extension and if LWS_WITH_HTTP_STREAM_COMPRESSION)\n@@ -1977,7 +1990,7 @@ if (LWS_WITH_SSL)\n \t\t\t\tinclude_directories(\u0022${inc}\u0022 \u0022${inc}/wolfssl\u0022)\n \t\t\tendforeach()\n \t\tendif()\n-\t\tset(CMAKE_REQUIRED_INCLUDES ${OPENSSL_INCLUDE_DIRS})\n+\t\tset(CMAKE_REQUIRED_INCLUDES ${CMAKE_REQUIRED_INCLUDES} ${OPENSSL_INCLUDE_DIRS})\n \t\tset(VARIA wolfSSL_)\n \n \t\tlist(APPEND LIB_LIST \u0022${WOLFSSL_LIBRARIES}\u0022)\n@@ -2020,7 +2033,7 @@ if (LWS_WITH_SSL)\n \n \tif (NOT LWS_WITH_MBEDTLS)\n \t\t# older (0.98) Openssl lacks this\n-\t\tset(CMAKE_REQUIRED_INCLUDES ${OPENSSL_INCLUDE_DIRS})\n+\t\tset(CMAKE_REQUIRED_INCLUDES ${CMAKE_REQUIRED_INCLUDES} ${OPENSSL_INCLUDE_DIRS})\n \t\tcheck_include_file(openssl/ecdh.h LWS_HAVE_OPENSSL_ECDH_H)\n \n \t\tif (LWS_SSL_SERVER_WITH_ECDH_CERT AND NOT LWS_HAVE_OPENSSL_ECDH_H)\n@@ -2181,7 +2194,7 @@ foreach (lib ${LWS_LIBRARIES})\n endforeach()\n \n set (temp ${CMAKE_REQUIRED_LIBRARIES})\n-set(CMAKE_REQUIRED_LIBRARIES ${LIB_LIST})\n+set(CMAKE_REQUIRED_LIBRARIES ${LIB_LIST} ${CMAKE_REQUIRED_LIBRARIES})\n \n if (LWS_WITH_ZLIB)\n \tif (LWS_WITH_BUNDLED_ZLIB)\ndiff --git a/READMEs/README.build-windows.md b/READMEs/README.build-windows.md\nindex 677e1f8..7b85369 100644\n--- a/READMEs/README.build-windows.md\n+++ b/READMEs/README.build-windows.md\n@@ -73,3 +73,22 @@ there.\n ```\n \n After that you can run the test apps OK.\n+\n+## pthreads\n+\n+It's amazing but after all these years windows doesn't offer pthreads compatibility\n+itself. Just like the many other missing POSIX bits like fork().\n+\n+I downloaded the latest (2012) zip release of pthreads-win32 from here\n+\n+ftp://sourceware.org/pub/pthreads-win32\n+\n+Then I created a dir \u0022C:\u005cProgram Files (x86)\u005cpthreads\u0022, and copied the `dll`,\n+`include` and `lib` subdirs from the `prebuilt` folder in the zip there.\n+\n+The cmake incantation to build against pthreads set up like that is\n+\n+```\n+ $ cmake .. -DLWS_EXT_PTHREAD_INCLUDE_DIR\u003d\u0022C:\u005cProgram Files (x86)\u005cpthreads\u005cinclude\u0022 -DLWS_EXT_PTHREAD_LIBRARIES\u003d\u0022C:\u005cProgram Files (x86)\u005cpthreads\u005clib\u005cx64\u005clibpthreadGC2.a\u0022 -DLWS_WITH_MINIMAL_EXAMPLES\u003d1\n+```\n+\ndiff --git a/cmake/lws_config.h.in b/cmake/lws_config.h.in\nindex 1788576..de5e2f6 100644\n--- a/cmake/lws_config.h.in\n+++ b/cmake/lws_config.h.in\n@@ -18,6 +18,8 @@\n \n #cmakedefine LWS_LIBRARY_VERSION_NUMBER\n \n+#cmakedefine LWS_EXT_PTHREAD_LIBRARIES\n+\n #cmakedefine LWS_AVOID_SIGPIPE_IGN\n #cmakedefine LWS_BUILD_HASH \u0022${LWS_BUILD_HASH}\u0022\n #cmakedefine LWS_BUILTIN_GETIFADDRS\ndiff --git a/lib/misc/threadpool/threadpool.c b/lib/misc/threadpool/threadpool.c\nindex deab757..61048ba 100644\n--- a/lib/misc/threadpool/threadpool.c\n+++ b/lib/misc/threadpool/threadpool.c\n@@ -26,6 +26,12 @@\n #define _GNU_SOURCE\n #endif\n \n+#if defined(WIN32)\n+#define HAVE_STRUCT_TIMESPEC\n+#if defined(pid_t)\n+#undef pid_t\n+#endif\n+#endif\n #include \u003cpthread.h\u003e\n \n #include \u0022private-lib-core.h\u0022\n@@ -131,10 +137,10 @@ __lws_threadpool_task_dump(struct lws_threadpool_task *task, char *buf, int len)\n \t}\n \n \tif (task-\u003eacc_running)\n-\t\trunms \u003d task-\u003eacc_running;\n+\t\trunms \u003d (int)task-\u003eacc_running;\n \n \tif (task-\u003eacc_syncing)\n-\t\tsyncms \u003d task-\u003eacc_syncing;\n+\t\tsyncms \u003d (int)task-\u003eacc_syncing;\n \n \tif (!task-\u003edone) {\n \t\tbuf +\u003d lws_snprintf(buf, end - buf,\ndiff --git a/minimal-examples/http-client/minimal-http-client-attach/CMakeLists.txt b/minimal-examples/http-client/minimal-http-client-attach/CMakeLists.txt\nindex a033c3d..822bfbb 100644\n--- a/minimal-examples/http-client/minimal-http-client-attach/CMakeLists.txt\n+++ b/minimal-examples/http-client/minimal-http-client-attach/CMakeLists.txt\n@@ -16,6 +16,12 @@ MACRO(require_pthreads result)\n \t\telse()\n \t\t\tmessage(FATAL_ERROR \u0022threading support requires pthreads\u0022)\n \t\tendif()\n+\telse()\n+\t\tif (WIN32)\n+\t\t\tset(PTHREAD_LIB ${LWS_EXT_PTHREAD_LIBRARIES})\n+\t\telse()\n+\t\t\tset(PTHREAD_LIB pthread)\n+\t\tendif()\n \tendif()\n ENDMACRO()\n \n@@ -88,9 +94,9 @@ if (requirements)\n \tadd_executable(${SAMP} ${SRCS})\n \n \tif (websockets_shared)\n-\t\ttarget_link_libraries(${SAMP} websockets_shared pthread)\n+\t\ttarget_link_libraries(${SAMP} websockets_shared ${PTHREAD_LIB})\n \t\tadd_dependencies(${SAMP} websockets_shared)\n \telse()\n-\t\ttarget_link_libraries(${SAMP} websockets pthread)\n+\t\ttarget_link_libraries(${SAMP} websockets ${PTHREAD_LIB})\n \tendif()\n endif()\ndiff --git a/minimal-examples/http-client/minimal-http-client-attach/minimal-http-client-attach.c b/minimal-examples/http-client/minimal-http-client-attach/minimal-http-client-attach.c\nindex dfd0032..20a0352 100644\n--- a/minimal-examples/http-client/minimal-http-client-attach/minimal-http-client-attach.c\n+++ b/minimal-examples/http-client/minimal-http-client-attach/minimal-http-client-attach.c\n@@ -15,6 +15,12 @@\n #include \u003clibwebsockets.h\u003e\n #include \u003cstring.h\u003e\n #include \u003csignal.h\u003e\n+#if defined(WIN32)\n+#define HAVE_STRUCT_TIMESPEC\n+#if defined(pid_t)\n+#undef pid_t\n+#endif\n+#endif\n #include \u003cpthread.h\u003e\n \n static struct lws_context *context;\n@@ -119,10 +125,7 @@ attach_callback(struct lws_context *context, int tsi, void *opaque)\n \t/*\n \t * Even though it was asked for from a different thread, we are called\n \t * back by lws from the lws event loop thread context\n-\t */\n-\tlwsl_user(\u0022%s: called from tid %p\u005cn\u0022, __func__, (void *)pthread_self());\n-\n-\t/*\n+\t *\n \t * We can set up our operations on the lws event loop and return so\n \t * they can happen asynchronously\n \t */\n@@ -218,7 +221,6 @@ int main(int argc, const char **argv)\n \t\tlogs \u003d atoi(p);\n \n \tlws_set_log_level(logs, NULL);\n-\tlwsl_user(\u0022%s: main thread tid %p\u005cn\u0022, __func__, (void *)pthread_self());\n \tlwsl_user(\u0022LWS minimal http client attach\u005cn\u0022);\n \n \tpthread_mutex_init(\u0026lock, NULL);\ndiff --git a/minimal-examples/http-server/minimal-http-server-eventlib-smp/CMakeLists.txt b/minimal-examples/http-server/minimal-http-server-eventlib-smp/CMakeLists.txt\nindex 3611a79..25c0b31 100644\n--- a/minimal-examples/http-server/minimal-http-server-eventlib-smp/CMakeLists.txt\n+++ b/minimal-examples/http-server/minimal-http-server-eventlib-smp/CMakeLists.txt\n@@ -15,6 +15,12 @@ MACRO(require_pthreads result)\n \t\telse()\n \t\t\tmessage(FATAL_ERROR \u0022threading support requires pthreads\u0022)\n \t\tendif()\n+\telse()\n+\t\tif (WIN32)\n+\t\t\tset(PTHREAD_LIB ${LWS_EXT_PTHREAD_LIBRARIES})\n+\t\telse()\n+\t\t\tset(PTHREAD_LIB pthread)\n+\t\tendif()\n \tendif()\n ENDMACRO()\n \n@@ -85,9 +91,9 @@ if (requirements)\n \tadd_executable(${SAMP} ${SRCS})\n \n \tif (websockets_shared)\n-\t\ttarget_link_libraries(${SAMP} websockets_shared pthread)\n-\t\tadd_dependencies(${SAMP} websockets_shared pthread)\n+\t\ttarget_link_libraries(${SAMP} websockets_shared ${PTHREAD_LIB})\n+\t\tadd_dependencies(${SAMP} websockets_shared ${PTHREAD_LIB})\n \telse()\n-\t\ttarget_link_libraries(${SAMP} websockets pthread)\n+\t\ttarget_link_libraries(${SAMP} websockets ${PTHREAD_LIB})\n \tendif()\n endif()\ndiff --git a/minimal-examples/http-server/minimal-http-server-eventlib-smp/minimal-http-server-eventlib-smp.c b/minimal-examples/http-server/minimal-http-server-eventlib-smp/minimal-http-server-eventlib-smp.c\nindex 6ea9b6e..f82fa04 100644\n--- a/minimal-examples/http-server/minimal-http-server-eventlib-smp/minimal-http-server-eventlib-smp.c\n+++ b/minimal-examples/http-server/minimal-http-server-eventlib-smp/minimal-http-server-eventlib-smp.c\n@@ -18,6 +18,13 @@\n #include \u003cstring.h\u003e\n #include \u003csignal.h\u003e\n \n+#if defined(WIN32)\n+#define HAVE_STRUCT_TIMESPEC\n+#if defined(pid_t)\n+#undef pid_t\n+#endif\n+#endif\n+\n #include \u003cpthread.h\u003e\n \n #define COUNT_THREADS 8\ndiff --git a/minimal-examples/http-server/minimal-http-server-smp/CMakeLists.txt b/minimal-examples/http-server/minimal-http-server-smp/CMakeLists.txt\nindex b32eb70..ab9c833 100644\n--- a/minimal-examples/http-server/minimal-http-server-smp/CMakeLists.txt\n+++ b/minimal-examples/http-server/minimal-http-server-smp/CMakeLists.txt\n@@ -15,6 +15,12 @@ MACRO(require_pthreads result)\n \t\telse()\n \t\t\tmessage(FATAL_ERROR \u0022threading support requires pthreads\u0022)\n \t\tendif()\n+\telse()\n+\t\tif (WIN32)\n+\t\t\tset(PTHREAD_LIB ${LWS_EXT_PTHREAD_LIBRARIES})\n+\t\telse()\n+\t\t\tset(PTHREAD_LIB pthread)\n+\t\tendif()\n \tendif()\n ENDMACRO()\n \n@@ -85,9 +91,9 @@ if (requirements)\n \tadd_executable(${SAMP} ${SRCS})\n \n \tif (websockets_shared)\n-\t\ttarget_link_libraries(${SAMP} websockets_shared pthread)\n-\t\tadd_dependencies(${SAMP} websockets_shared pthread)\n+\t\ttarget_link_libraries(${SAMP} websockets_shared ${PTHREAD_LIB})\n+\t\tadd_dependencies(${SAMP} websockets_shared)\n \telse()\n-\t\ttarget_link_libraries(${SAMP} websockets pthread)\n+\t\ttarget_link_libraries(${SAMP} websockets ${PTHREAD_LIB})\n \tendif()\n endif()\n\u005c No newline at end of file\ndiff --git a/minimal-examples/http-server/minimal-http-server-smp/minimal-http-server-smp.c b/minimal-examples/http-server/minimal-http-server-smp/minimal-http-server-smp.c\nindex ae07e4a..b6a3441 100644\n--- a/minimal-examples/http-server/minimal-http-server-smp/minimal-http-server-smp.c\n+++ b/minimal-examples/http-server/minimal-http-server-smp/minimal-http-server-smp.c\n@@ -21,6 +21,12 @@\n #include \u003clibwebsockets.h\u003e\n #include \u003cstring.h\u003e\n #include \u003csignal.h\u003e\n+#if defined(WIN32)\n+#define HAVE_STRUCT_TIMESPEC\n+#if defined(pid_t)\n+#undef pid_t\n+#endif\n+#endif\n #include \u003cpthread.h\u003e\n \n #define COUNT_THREADS 8\ndiff --git a/minimal-examples/http-server/minimal-http-server-sse-ring/CMakeLists.txt b/minimal-examples/http-server/minimal-http-server-sse-ring/CMakeLists.txt\nindex be14a0d..384f0a7 100644\n--- a/minimal-examples/http-server/minimal-http-server-sse-ring/CMakeLists.txt\n+++ b/minimal-examples/http-server/minimal-http-server-sse-ring/CMakeLists.txt\n@@ -15,6 +15,12 @@ MACRO(require_pthreads result)\n \t\telse()\n \t\t\tmessage(FATAL_ERROR \u0022threading support requires pthreads\u0022)\n \t\tendif()\n+\telse()\n+\t\tif (WIN32)\n+\t\t\tset(PTHREAD_LIB ${LWS_EXT_PTHREAD_LIBRARIES})\n+\t\telse()\n+\t\t\tset(PTHREAD_LIB pthread)\n+\t\tendif()\n \tendif()\n ENDMACRO()\n \n@@ -85,9 +91,9 @@ if (requirements)\n \tadd_executable(${SAMP} ${SRCS})\n \n \tif (websockets_shared)\n-\t\ttarget_link_libraries(${SAMP} websockets_shared pthread)\n+\t\ttarget_link_libraries(${SAMP} websockets_shared ${PTHREAD_LIB})\n \t\tadd_dependencies(${SAMP} websockets_shared)\n \telse()\n-\t\ttarget_link_libraries(${SAMP} websockets pthread)\n+\t\ttarget_link_libraries(${SAMP} websockets ${PTHREAD_LIB})\n \tendif()\n endif()\ndiff --git a/minimal-examples/http-server/minimal-http-server-sse-ring/minimal-http-server-sse-ring.c b/minimal-examples/http-server/minimal-http-server-sse-ring/minimal-http-server-sse-ring.c\nindex 2e51c2f..1d4f210 100644\n--- a/minimal-examples/http-server/minimal-http-server-sse-ring/minimal-http-server-sse-ring.c\n+++ b/minimal-examples/http-server/minimal-http-server-sse-ring/minimal-http-server-sse-ring.c\n@@ -19,6 +19,12 @@\n #include \u003cstring.h\u003e\n #include \u003cstdlib.h\u003e\n #include \u003csignal.h\u003e\n+#if defined(WIN32)\n+#define HAVE_STRUCT_TIMESPEC\n+#if defined(pid_t)\n+#undef pid_t\n+#endif\n+#endif\n #include \u003cpthread.h\u003e\n #include \u003ctime.h\u003e\n \n@@ -86,7 +92,11 @@ thread_spam(void *d)\n {\n \tstruct vhd *vhd \u003d (struct vhd *)d;\n \tstruct msg amsg;\n-\tint len \u003d 128, index \u003d 1, n;\n+\tint len \u003d 128, index \u003d 1, n, whoami \u003d 0;\n+\n+\tfor (n \u003d 0; n \u003c (int)LWS_ARRAY_SIZE(vhd-\u003epthread_spam); n++)\n+\t\tif (pthread_equal(pthread_self(), vhd-\u003epthread_spam[n]))\n+\t\t\twhoami \u003d n + 1;\n \n \tdo {\n \t\t/* don't generate output if nobody connected */\n@@ -108,10 +118,9 @@ thread_spam(void *d)\n \t\t\tgoto wait_unlock;\n \t\t}\n \t\tn \u003d lws_snprintf((char *)amsg.payload, len,\n-\t\t\t \u0022%s: tid: %p, msg: %d\u0022, __func__,\n-\t\t\t (void *)pthread_self(), index++);\n+\t\t\t \u0022%s: tid: %d, msg: %d\u0022, __func__, whoami, index++);\n \t\tamsg.len \u003d n;\n-\t\tn \u003d lws_ring_insert(vhd-\u003ering, \u0026amsg, 1);\n+\t\tn \u003d (int)lws_ring_insert(vhd-\u003ering, \u0026amsg, 1);\n \t\tif (n !\u003d 1) {\n \t\t\t__minimal_destroy_message(\u0026amsg);\n \t\t\tlwsl_user(\u0022dropping!\u005cn\u0022);\n@@ -131,7 +140,7 @@ wait:\n \n \t} while (!vhd-\u003efinished);\n \n-\tlwsl_notice(\u0022thread_spam %p exiting\u005cn\u0022, (void *)pthread_self());\n+\tlwsl_notice(\u0022thread_spam %d exiting\u005cn\u0022, whoami);\n \n \tpthread_exit(NULL);\n \n@@ -186,8 +195,7 @@ callback_sse(struct lws *wsi, enum lws_callback_reasons reason, void *user,\n \t\tinit_fail:\n \t\tvhd-\u003efinished \u003d 1;\n \t\tfor (n \u003d 0; n \u003c (int)LWS_ARRAY_SIZE(vhd-\u003epthread_spam); n++)\n-\t\t\tif (vhd-\u003epthread_spam[n])\n-\t\t\t\tpthread_join(vhd-\u003epthread_spam[n], \u0026retval);\n+\t\t\tpthread_join(vhd-\u003epthread_spam[n], \u0026retval);\n \n \t\tif (vhd-\u003ering)\n \t\t\tlws_ring_destroy(vhd-\u003ering);\ndiff --git a/minimal-examples/http-server/minimal-http-server-sse/CMakeLists.txt b/minimal-examples/http-server/minimal-http-server-sse/CMakeLists.txt\nindex 35e819f..781ae30 100644\n--- a/minimal-examples/http-server/minimal-http-server-sse/CMakeLists.txt\n+++ b/minimal-examples/http-server/minimal-http-server-sse/CMakeLists.txt\n@@ -14,6 +14,12 @@ MACRO(require_pthreads result)\n \t\telse()\n \t\t\tmessage(FATAL_ERROR \u0022threading support requires pthreads\u0022)\n \t\tendif()\n+\telse()\n+\t\tif (WIN32)\n+\t\t\tset(PTHREAD_LIB ${LWS_EXT_PTHREAD_LIBRARIES})\n+\t\telse()\n+\t\t\tset(PTHREAD_LIB pthread)\n+\t\tendif()\n \tendif()\n ENDMACRO()\n \n@@ -84,9 +90,9 @@ if (requirements)\n \tadd_executable(${SAMP} ${SRCS})\n \n \tif (websockets_shared)\n-\t\ttarget_link_libraries(${SAMP} websockets_shared)\n+\t\ttarget_link_libraries(${SAMP} websockets_shared ${PTHREAD_LIB})\n \t\tadd_dependencies(${SAMP} websockets_shared)\n \telse()\n-\t\ttarget_link_libraries(${SAMP} websockets)\n+\t\ttarget_link_libraries(${SAMP} websockets ${PTHREAD_LIB})\n \tendif()\n endif()\ndiff --git a/minimal-examples/http-server/minimal-http-server-sse/minimal-http-server-sse.c b/minimal-examples/http-server/minimal-http-server-sse/minimal-http-server-sse.c\nindex cb60774..c7f8e7d 100644\n--- a/minimal-examples/http-server/minimal-http-server-sse/minimal-http-server-sse.c\n+++ b/minimal-examples/http-server/minimal-http-server-sse/minimal-http-server-sse.c\n@@ -19,6 +19,12 @@\n #include \u003cstring.h\u003e\n #include \u003csignal.h\u003e\n #include \u003ctime.h\u003e\n+#if defined(WIN32)\n+#define HAVE_STRUCT_TIMESPEC\n+#if defined(pid_t)\n+#undef pid_t\n+#endif\n+#endif\n #include \u003cpthread.h\u003e\n \n /*\ndiff --git a/minimal-examples/mqtt-client/minimal-mqtt-client-multi/minimal-mqtt-client-multi.c b/minimal-examples/mqtt-client/minimal-mqtt-client-multi/minimal-mqtt-client-multi.c\nindex 1659a21..ab6967f 100644\n--- a/minimal-examples/mqtt-client/minimal-mqtt-client-multi/minimal-mqtt-client-multi.c\n+++ b/minimal-examples/mqtt-client/minimal-mqtt-client-multi/minimal-mqtt-client-multi.c\n@@ -11,6 +11,12 @@\n #include \u003clibwebsockets.h\u003e\n #include \u003cstring.h\u003e\n #include \u003csignal.h\u003e\n+#if defined(WIN32)\n+#define HAVE_STRUCT_TIMESPEC\n+#if defined(pid_t)\n+#undef pid_t\n+#endif\n+#endif\n #include \u003cpthread.h\u003e\n #include \u003cassert.h\u003e\n \ndiff --git a/minimal-examples/mqtt-client/minimal-mqtt-client/minimal-mqtt-client.c b/minimal-examples/mqtt-client/minimal-mqtt-client/minimal-mqtt-client.c\nindex d5fc448..8cbce65 100644\n--- a/minimal-examples/mqtt-client/minimal-mqtt-client/minimal-mqtt-client.c\n+++ b/minimal-examples/mqtt-client/minimal-mqtt-client/minimal-mqtt-client.c\n@@ -11,6 +11,12 @@\n #include \u003clibwebsockets.h\u003e\n #include \u003cstring.h\u003e\n #include \u003csignal.h\u003e\n+#if defined(WIN32)\n+#define HAVE_STRUCT_TIMESPEC\n+#if defined(pid_t)\n+#undef pid_t\n+#endif\n+#endif\n #include \u003cpthread.h\u003e\n #include \u003cassert.h\u003e\n \ndiff --git a/minimal-examples/ws-client/minimal-ws-client-ping/CMakeLists.txt b/minimal-examples/ws-client/minimal-ws-client-ping/CMakeLists.txt\nindex f40d630..c6d1133 100644\n--- a/minimal-examples/ws-client/minimal-ws-client-ping/CMakeLists.txt\n+++ b/minimal-examples/ws-client/minimal-ws-client-ping/CMakeLists.txt\n@@ -15,8 +15,15 @@ MACRO(require_pthreads result)\n \t\telse()\n \t\t\tmessage(FATAL_ERROR \u0022threading support requires pthreads\u0022)\n \t\tendif()\n+\telse()\n+\t\tif (WIN32)\n+\t\t\tset(PTHREAD_LIB ${LWS_EXT_PTHREAD_LIBRARIES})\n+\t\telse()\n+\t\t\tset(PTHREAD_LIB pthread)\n+\t\tendif()\n \tendif()\n ENDMACRO()\n+\n # If we are being built as part of lws, confirm current build config supports\n # reqconfig, else skip building ourselves.\n #\n@@ -84,9 +91,9 @@ if (requirements)\n \tadd_executable(${SAMP} ${SRCS})\n \n \tif (websockets_shared)\n-\t\ttarget_link_libraries(${SAMP} websockets_shared pthread)\n-\t\tadd_dependencies(${SAMP} websockets_shared pthread)\n+\t\ttarget_link_libraries(${SAMP} websockets_shared ${PTHREAD_LIB})\n+\t\tadd_dependencies(${SAMP} websockets_shared)\n \telse()\n-\t\ttarget_link_libraries(${SAMP} websockets pthread)\n+\t\ttarget_link_libraries(${SAMP} websockets ${PTHREAD_LIB})\n \tendif()\n endif()\ndiff --git a/minimal-examples/ws-client/minimal-ws-client-ping/minimal-ws-client-ping.c b/minimal-examples/ws-client/minimal-ws-client-ping/minimal-ws-client-ping.c\nindex a8589f0..ff6107b 100644\n--- a/minimal-examples/ws-client/minimal-ws-client-ping/minimal-ws-client-ping.c\n+++ b/minimal-examples/ws-client/minimal-ws-client-ping/minimal-ws-client-ping.c\n@@ -14,6 +14,12 @@\n #include \u003clibwebsockets.h\u003e\n #include \u003cstring.h\u003e\n #include \u003csignal.h\u003e\n+#if defined(WIN32)\n+#define HAVE_STRUCT_TIMESPEC\n+#if defined(pid_t)\n+#undef pid_t\n+#endif\n+#endif\n #include \u003cpthread.h\u003e\n \n static struct lws_context *context;\ndiff --git a/minimal-examples/ws-client/minimal-ws-client-spam/CMakeLists.txt b/minimal-examples/ws-client/minimal-ws-client-spam/CMakeLists.txt\nindex da3c51b..42fd970 100644\n--- a/minimal-examples/ws-client/minimal-ws-client-spam/CMakeLists.txt\n+++ b/minimal-examples/ws-client/minimal-ws-client-spam/CMakeLists.txt\n@@ -15,8 +15,15 @@ MACRO(require_pthreads result)\n \t\telse()\n \t\t\tmessage(FATAL_ERROR \u0022threading support requires pthreads\u0022)\n \t\tendif()\n+\telse()\n+\t\tif (WIN32)\n+\t\t\tset(PTHREAD_LIB ${LWS_EXT_PTHREAD_LIBRARIES})\n+\t\telse()\n+\t\t\tset(PTHREAD_LIB pthread)\n+\t\tendif()\n \tendif()\n ENDMACRO()\n+\n # If we are being built as part of lws, confirm current build config supports\n # reqconfig, else skip building ourselves.\n #\n@@ -84,9 +91,9 @@ if (requirements)\n \tadd_executable(${SAMP} ${SRCS})\n \n \tif (websockets_shared)\n-\t\ttarget_link_libraries(${SAMP} websockets_shared pthread)\n-\t\tadd_dependencies(${SAMP} websockets_shared pthread)\n+\t\ttarget_link_libraries(${SAMP} websockets_shared ${PTHREAD_LIB})\n+\t\tadd_dependencies(${SAMP} websockets_shared)\n \telse()\n-\t\ttarget_link_libraries(${SAMP} websockets pthread)\n+\t\ttarget_link_libraries(${SAMP} websockets ${PTHREAD_LIB})\n \tendif()\n endif()\ndiff --git a/minimal-examples/ws-client/minimal-ws-client-spam/minimal-ws-client-spam.c b/minimal-examples/ws-client/minimal-ws-client-spam/minimal-ws-client-spam.c\nindex ec6f523..3809ef5 100644\n--- a/minimal-examples/ws-client/minimal-ws-client-spam/minimal-ws-client-spam.c\n+++ b/minimal-examples/ws-client/minimal-ws-client-spam/minimal-ws-client-spam.c\n@@ -13,6 +13,12 @@\n #include \u003clibwebsockets.h\u003e\n #include \u003cstring.h\u003e\n #include \u003csignal.h\u003e\n+#if defined(WIN32)\n+#define HAVE_STRUCT_TIMESPEC\n+#if defined(pid_t)\n+#undef pid_t\n+#endif\n+#endif\n #include \u003cpthread.h\u003e\n \n enum {\ndiff --git a/minimal-examples/ws-client/minimal-ws-client-tx/CMakeLists.txt b/minimal-examples/ws-client/minimal-ws-client-tx/CMakeLists.txt\nindex 6d9c818..70fd5e2 100644\n--- a/minimal-examples/ws-client/minimal-ws-client-tx/CMakeLists.txt\n+++ b/minimal-examples/ws-client/minimal-ws-client-tx/CMakeLists.txt\n@@ -15,8 +15,15 @@ MACRO(require_pthreads result)\n \t\telse()\n \t\t\tmessage(FATAL_ERROR \u0022threading support requires pthreads\u0022)\n \t\tendif()\n+\telse()\n+\t\tif (WIN32)\n+\t\t\tset(PTHREAD_LIB ${LWS_EXT_PTHREAD_LIBRARIES})\n+\t\telse()\n+\t\t\tset(PTHREAD_LIB pthread)\n+\t\tendif()\n \tendif()\n ENDMACRO()\n+\n # If we are being built as part of lws, confirm current build config supports\n # reqconfig, else skip building ourselves.\n #\n@@ -84,9 +91,9 @@ if (requirements)\n \tadd_executable(${SAMP} ${SRCS})\n \n \tif (websockets_shared)\n-\t\ttarget_link_libraries(${SAMP} websockets_shared pthread)\n-\t\tadd_dependencies(${SAMP} websockets_shared pthread)\n+\t\ttarget_link_libraries(${SAMP} websockets_shared ${PTHREAD_LIB})\n+\t\tadd_dependencies(${SAMP} websockets_shared)\n \telse()\n-\t\ttarget_link_libraries(${SAMP} websockets pthread)\n+\t\ttarget_link_libraries(${SAMP} websockets ${PTHREAD_LIB})\n \tendif()\n endif()\n\u005c No newline at end of file\ndiff --git a/minimal-examples/ws-client/minimal-ws-client-tx/minimal-ws-client.c b/minimal-examples/ws-client/minimal-ws-client-tx/minimal-ws-client.c\nindex 137201d..c83e23e 100644\n--- a/minimal-examples/ws-client/minimal-ws-client-tx/minimal-ws-client.c\n+++ b/minimal-examples/ws-client/minimal-ws-client-tx/minimal-ws-client.c\n@@ -21,6 +21,12 @@\n #include \u003clibwebsockets.h\u003e\n #include \u003cstring.h\u003e\n #include \u003csignal.h\u003e\n+#if defined(WIN32)\n+#define HAVE_STRUCT_TIMESPEC\n+#if defined(pid_t)\n+#undef pid_t\n+#endif\n+#endif\n #include \u003cpthread.h\u003e\n \n static int interrupted;\n@@ -70,7 +76,11 @@ thread_spam(void *d)\n \tstruct per_vhost_data__minimal *vhd \u003d\n \t\t\t(struct per_vhost_data__minimal *)d;\n \tstruct msg amsg;\n-\tint len \u003d 128, index \u003d 1, n;\n+\tint len \u003d 128, index \u003d 1, n, whoami \u003d 0;\n+\n+\tfor (n \u003d 0; n \u003c (int)LWS_ARRAY_SIZE(vhd-\u003epthread_spam); n++)\n+\t\tif (pthread_equal(pthread_self(), vhd-\u003epthread_spam[n]))\n+\t\t\twhoami \u003d n + 1;\n \n \tdo {\n \t\t/* don't generate output if client not connected */\n@@ -92,10 +102,9 @@ thread_spam(void *d)\n \t\t\tgoto wait_unlock;\n \t\t}\n \t\tn \u003d lws_snprintf((char *)amsg.payload + LWS_PRE, len,\n-\t\t\t \u0022tid: %p, msg: %d\u0022,\n-\t\t\t (void *)pthread_self(), index++);\n+\t\t\t \u0022tid: %d, msg: %d\u0022, whoami, index++);\n \t\tamsg.len \u003d n;\n-\t\tn \u003d lws_ring_insert(vhd-\u003ering, \u0026amsg, 1);\n+\t\tn \u003d (int)lws_ring_insert(vhd-\u003ering, \u0026amsg, 1);\n \t\tif (n !\u003d 1) {\n \t\t\t__minimal_destroy_message(\u0026amsg);\n \t\t\tlwsl_user(\u0022dropping!\u005cn\u0022);\n@@ -114,7 +123,7 @@ wait:\n \n \t} while (!vhd-\u003efinished);\n \n-\tlwsl_notice(\u0022thread_spam %p exiting\u005cn\u0022, (void *)pthread_self());\n+\tlwsl_notice(\u0022thread_spam %d exiting\u005cn\u0022, whoami);\n \n \tpthread_exit(NULL);\n \n@@ -188,8 +197,7 @@ callback_minimal_broker(struct lws *wsi, enum lws_callback_reasons reason,\n init_fail:\n \t\tvhd-\u003efinished \u003d 1;\n \t\tfor (n \u003d 0; n \u003c (int)LWS_ARRAY_SIZE(vhd-\u003epthread_spam); n++)\n-\t\t\tif (vhd-\u003epthread_spam[n])\n-\t\t\t\tpthread_join(vhd-\u003epthread_spam[n], \u0026retval);\n+\t\t\tpthread_join(vhd-\u003epthread_spam[n], \u0026retval);\n \n \t\tif (vhd-\u003ering)\n \t\t\tlws_ring_destroy(vhd-\u003ering);\ndiff --git a/minimal-examples/ws-server/minimal-ws-server-threadpool/CMakeLists.txt b/minimal-examples/ws-server/minimal-ws-server-threadpool/CMakeLists.txt\nindex 111ba70..f557ca2 100644\n--- a/minimal-examples/ws-server/minimal-ws-server-threadpool/CMakeLists.txt\n+++ b/minimal-examples/ws-server/minimal-ws-server-threadpool/CMakeLists.txt\n@@ -15,6 +15,12 @@ MACRO(require_pthreads result)\n \t\telse()\n \t\t\tmessage(FATAL_ERROR \u0022threading support requires pthreads\u0022)\n \t\tendif()\n+\telse()\n+\t\tif (WIN32)\n+\t\t\tset(PTHREAD_LIB ${LWS_EXT_PTHREAD_LIBRARIES})\n+\t\telse()\n+\t\t\tset(PTHREAD_LIB pthread)\n+\t\tendif()\n \tendif()\n ENDMACRO()\n \n@@ -86,9 +92,9 @@ if (requirements)\n \tadd_executable(${SAMP} ${SRCS})\n \n \tif (websockets_shared)\n-\t\ttarget_link_libraries(${SAMP} websockets_shared pthread)\n+\t\ttarget_link_libraries(${SAMP} websockets_shared ${PTHREAD_LIB})\n \t\tadd_dependencies(${SAMP} websockets_shared)\n \telse()\n-\t\ttarget_link_libraries(${SAMP} websockets pthread)\n+\t\ttarget_link_libraries(${SAMP} websockets ${PTHREAD_LIB})\n \tendif()\n endif()\ndiff --git a/minimal-examples/ws-server/minimal-ws-server-threadpool/minimal-ws-server-threadpool.c b/minimal-examples/ws-server/minimal-ws-server-threadpool/minimal-ws-server-threadpool.c\nindex e0d8a9d..61beb54 100644\n--- a/minimal-examples/ws-server/minimal-ws-server-threadpool/minimal-ws-server-threadpool.c\n+++ b/minimal-examples/ws-server/minimal-ws-server-threadpool/minimal-ws-server-threadpool.c\n@@ -21,6 +21,12 @@\n #include \u003clibwebsockets.h\u003e\n #include \u003cstring.h\u003e\n #include \u003csignal.h\u003e\n+#if defined(WIN32)\n+#define HAVE_STRUCT_TIMESPEC\n+#if defined(pid_t)\n+#undef pid_t\n+#endif\n+#endif\n #include \u003cpthread.h\u003e\n \n #define LWS_PLUGIN_STATIC\n@@ -125,5 +131,7 @@ int main(int argc, const char **argv)\n \n \tlws_context_destroy(context);\n \n+\tlwsl_user(\u0022%s: exiting cleanly...\u005cn\u0022, __func__);\n+\n \treturn 0;\n }\ndiff --git a/minimal-examples/ws-server/minimal-ws-server-threadpool/protocol_lws_minimal_threadpool.c b/minimal-examples/ws-server/minimal-ws-server-threadpool/protocol_lws_minimal_threadpool.c\nindex 55998a7..5fd7d87 100644\n--- a/minimal-examples/ws-server/minimal-ws-server-threadpool/protocol_lws_minimal_threadpool.c\n+++ b/minimal-examples/ws-server/minimal-ws-server-threadpool/protocol_lws_minimal_threadpool.c\n@@ -43,6 +43,10 @@ struct task_data {\n \tuint64_t pos, end;\n };\n \n+#if defined(WIN32)\n+static void usleep(unsigned long l) { Sleep(l / 1000); }\n+#endif\n+\n /*\n * Create the private data for the task\n *\n@@ -254,6 +258,8 @@ callback_minimal(struct lws *wsi, enum lws_callback_reasons reason,\n \t\t */\n \n \t\ttask \u003d lws_threadpool_get_task_wsi(wsi);\n+\t\tif (!task)\n+\t\t\tbreak;\n \t\tn \u003d lws_threadpool_task_status(task, \u0026_user);\n \t\tlwsl_debug(\u0022%s: LWS_CALLBACK_SERVER_WRITEABLE: status %d\u005cn\u0022,\n \t\t\t __func__, n);\n@@ -277,7 +283,7 @@ callback_minimal(struct lws *wsi, enum lws_callback_reasons reason,\n \n \t\tlws_set_timeout(wsi, PENDING_TIMEOUT_THREADPOOL_TASK, 5);\n \n-\t\tn \u003d strlen(priv-\u003eresult + LWS_PRE);\n+\t\tn \u003d (int)strlen(priv-\u003eresult + LWS_PRE);\n \t\tm \u003d lws_write(wsi, (unsigned char *)priv-\u003eresult + LWS_PRE,\n \t\t\t n, LWS_WRITE_TEXT);\n \t\tif (m \u003c n) {\ndiff --git a/minimal-examples/ws-server/minimal-ws-server-threads-smp/CMakeLists.txt b/minimal-examples/ws-server/minimal-ws-server-threads-smp/CMakeLists.txt\nindex a6c798f..bf2ef9d 100644\n--- a/minimal-examples/ws-server/minimal-ws-server-threads-smp/CMakeLists.txt\n+++ b/minimal-examples/ws-server/minimal-ws-server-threads-smp/CMakeLists.txt\n@@ -15,6 +15,12 @@ MACRO(require_pthreads result)\n \t\telse()\n \t\t\tmessage(FATAL_ERROR \u0022threading support requires pthreads\u0022)\n \t\tendif()\n+\telse()\n+\t\tif (WIN32)\n+\t\t\tset(PTHREAD_LIB ${LWS_EXT_PTHREAD_LIBRARIES})\n+\t\telse()\n+\t\t\tset(PTHREAD_LIB pthread)\n+\t\tendif()\n \tendif()\n ENDMACRO()\n \n@@ -85,9 +91,9 @@ if (requirements)\n \tadd_executable(${SAMP} ${SRCS})\n \n \tif (websockets_shared)\n-\t\ttarget_link_libraries(${SAMP} websockets_shared pthread)\n+\t\ttarget_link_libraries(${SAMP} websockets_shared ${PTHREAD_LIB})\n \t\tadd_dependencies(${SAMP} websockets_shared)\n \telse()\n-\t\ttarget_link_libraries(${SAMP} websockets pthread)\n+\t\ttarget_link_libraries(${SAMP} websockets ${PTHREAD_LIB})\n \tendif()\n endif()\ndiff --git a/minimal-examples/ws-server/minimal-ws-server-threads-smp/minimal-ws-server.c b/minimal-examples/ws-server/minimal-ws-server-threads-smp/minimal-ws-server.c\nindex 8303f5c..8a74eb7 100644\n--- a/minimal-examples/ws-server/minimal-ws-server-threads-smp/minimal-ws-server.c\n+++ b/minimal-examples/ws-server/minimal-ws-server-threads-smp/minimal-ws-server.c\n@@ -21,6 +21,12 @@\n #include \u003clibwebsockets.h\u003e\n #include \u003cstring.h\u003e\n #include \u003csignal.h\u003e\n+#if defined(WIN32)\n+#define HAVE_STRUCT_TIMESPEC\n+#if defined(pid_t)\n+#undef pid_t\n+#endif\n+#endif\n #include \u003cpthread.h\u003e\n \n #define LWS_PLUGIN_STATIC\ndiff --git a/minimal-examples/ws-server/minimal-ws-server-threads-smp/protocol_lws_minimal.c b/minimal-examples/ws-server/minimal-ws-server-threads-smp/protocol_lws_minimal.c\nindex 375530c..1ee7ce7 100644\n--- a/minimal-examples/ws-server/minimal-ws-server-threads-smp/protocol_lws_minimal.c\n+++ b/minimal-examples/ws-server/minimal-ws-server-threads-smp/protocol_lws_minimal.c\n@@ -83,7 +83,11 @@ thread_spam(void *d)\n \tstruct per_vhost_data__minimal *vhd \u003d\n \t\t\t(struct per_vhost_data__minimal *)d;\n \tstruct msg amsg;\n-\tint len \u003d 128, index \u003d 1, n;\n+\tint len \u003d 128, index \u003d 1, n, whoami \u003d 0;\n+\n+\tfor (n \u003d 0; n \u003c (int)LWS_ARRAY_SIZE(vhd-\u003epthread_spam); n++)\n+\t\tif (pthread_equal(pthread_self(), vhd-\u003epthread_spam[n]))\n+\t\t\twhoami \u003d n + 1;\n \n \tdo {\n \t\t/* don't generate output if nobody connected */\n@@ -105,10 +109,10 @@ thread_spam(void *d)\n \t\t\tgoto wait_unlock;\n \t\t}\n \t\tn \u003d lws_snprintf((char *)amsg.payload + LWS_PRE, len,\n-\t\t\t \u0022%s: spam tid: %p, msg: %d\u0022, vhd-\u003econfig,\n-\t\t\t (void *)pthread_self(), index++);\n+\t\t\t \u0022%s: spam tid: %d, msg: %d\u0022, vhd-\u003econfig,\n+\t\t\t whoami, index++);\n \t\tamsg.len \u003d n;\n-\t\tn \u003d lws_ring_insert(vhd-\u003ering, \u0026amsg, 1);\n+\t\tn \u003d (int)lws_ring_insert(vhd-\u003ering, \u0026amsg, 1);\n \t\tif (n !\u003d 1) {\n \t\t\t__minimal_destroy_message(\u0026amsg);\n \t\t\tlwsl_user(\u0022dropping!\u005cn\u0022);\n@@ -127,7 +131,7 @@ wait:\n \n \t} while (!vhd-\u003efinished);\n \n-\tlwsl_notice(\u0022thread_spam %p exiting\u005cn\u0022, (void *)pthread_self());\n+\tlwsl_notice(\u0022thread_spam %d exiting\u005cn\u0022, whoami);\n \n \tpthread_exit(NULL);\n \n@@ -199,8 +203,7 @@ callback_minimal(struct lws *wsi, enum lws_callback_reasons reason,\n init_fail:\n \t\tvhd-\u003efinished \u003d 1;\n \t\tfor (n \u003d 0; n \u003c (int)LWS_ARRAY_SIZE(vhd-\u003epthread_spam); n++)\n-\t\t\tif (vhd-\u003epthread_spam[n])\n-\t\t\t\tpthread_join(vhd-\u003epthread_spam[n], \u0026retval);\n+\t\t\tpthread_join(vhd-\u003epthread_spam[n], \u0026retval);\n \n \t\tif (vhd-\u003ering)\n \t\t\tlws_ring_destroy(vhd-\u003ering);\n@@ -231,7 +234,7 @@ init_fail:\n \t\t}\n \n \t\tn \u003d lws_snprintf(temp + LWS_PRE, sizeof(temp) - LWS_PRE,\n-\t\t\t \u0022svc tid:%p, %s\u0022, (void *)pthread_self(),\n+\t\t\t \u0022svc, %s\u0022,\n \t\t\t (char *)pmsg-\u003epayload + LWS_PRE);\n \n \t\t/* notice we allowed for LWS_PRE in the payload already */\n@@ -265,8 +268,7 @@ init_fail:\n \t\tbreak;\n \n \tcase LWS_CALLBACK_EVENT_WAIT_CANCELLED:\n-\t\tlwsl_notice(\u0022LWS_CALLBACK_EVENT_WAIT_CANCELLED in svc tid %p\u005cn\u0022,\n-\t\t\t\t(void *)pthread_self());\n+\t\tlwsl_notice(\u0022LWS_CALLBACK_EVENT_WAIT_CANCELLED in svc\u005cn\u0022);\n \t\tif (!vhd)\n \t\t\tbreak;\n \t\t/*\ndiff --git a/minimal-examples/ws-server/minimal-ws-server-threads/CMakeLists.txt b/minimal-examples/ws-server/minimal-ws-server-threads/CMakeLists.txt\nindex 283a182..c8bbb07 100644\n--- a/minimal-examples/ws-server/minimal-ws-server-threads/CMakeLists.txt\n+++ b/minimal-examples/ws-server/minimal-ws-server-threads/CMakeLists.txt\n@@ -15,6 +15,12 @@ MACRO(require_pthreads result)\n \t\telse()\n \t\t\tmessage(FATAL_ERROR \u0022threading support requires pthreads\u0022)\n \t\tendif()\n+\telse()\n+\t\tif (WIN32)\n+\t\t\tset(PTHREAD_LIB ${LWS_EXT_PTHREAD_LIBRARIES})\n+\t\telse()\n+\t\t\tset(PTHREAD_LIB pthread)\n+\t\tendif()\n \tendif()\n ENDMACRO()\n \n@@ -88,9 +94,9 @@ if (requirements)\n \tadd_executable(${SAMP} ${SRCS})\n \n \tif (websockets_shared)\n-\t\ttarget_link_libraries(${SAMP} websockets_shared pthread)\n+\t\ttarget_link_libraries(${SAMP} websockets_shared ${PTHREAD_LIB})\n \t\tadd_dependencies(${SAMP} websockets_shared)\n \telse()\n-\t\ttarget_link_libraries(${SAMP} websockets pthread)\n+\t\ttarget_link_libraries(${SAMP} websockets ${PTHREAD_LIB})\n \tendif()\n endif()\ndiff --git a/minimal-examples/ws-server/minimal-ws-server-threads/minimal-ws-server.c b/minimal-examples/ws-server/minimal-ws-server-threads/minimal-ws-server.c\nindex 40d7fc7..fb96a1b 100644\n--- a/minimal-examples/ws-server/minimal-ws-server-threads/minimal-ws-server.c\n+++ b/minimal-examples/ws-server/minimal-ws-server-threads/minimal-ws-server.c\n@@ -21,6 +21,12 @@\n #include \u003clibwebsockets.h\u003e\n #include \u003cstring.h\u003e\n #include \u003csignal.h\u003e\n+#if defined(WIN32)\n+#define HAVE_STRUCT_TIMESPEC\n+#if defined(pid_t)\n+#undef pid_t\n+#endif\n+#endif\n #include \u003cpthread.h\u003e\n \n #define LWS_PLUGIN_STATIC\ndiff --git a/minimal-examples/ws-server/minimal-ws-server-threads/protocol_lws_minimal.c b/minimal-examples/ws-server/minimal-ws-server-threads/protocol_lws_minimal.c\nindex f3d83da..8f230bb 100644\n--- a/minimal-examples/ws-server/minimal-ws-server-threads/protocol_lws_minimal.c\n+++ b/minimal-examples/ws-server/minimal-ws-server-threads/protocol_lws_minimal.c\n@@ -83,7 +83,11 @@ thread_spam(void *d)\n \tstruct per_vhost_data__minimal *vhd \u003d\n \t\t\t(struct per_vhost_data__minimal *)d;\n \tstruct msg amsg;\n-\tint len \u003d 128, index \u003d 1, n;\n+\tint len \u003d 128, index \u003d 1, n, whoami \u003d 0;\n+\n+\tfor (n \u003d 0; n \u003c (int)LWS_ARRAY_SIZE(vhd-\u003epthread_spam); n++)\n+\t\tif (pthread_equal(pthread_self(), vhd-\u003epthread_spam[n]))\n+\t\t\twhoami \u003d n + 1;\n \n \tdo {\n \t\t/* don't generate output if nobody connected */\n@@ -105,8 +109,8 @@ thread_spam(void *d)\n \t\t\tgoto wait_unlock;\n \t\t}\n \t\tn \u003d lws_snprintf((char *)amsg.payload + LWS_PRE, len,\n-\t\t\t \u0022%s: tid: %p, msg: %d\u0022, vhd-\u003econfig,\n-\t\t\t (void *)pthread_self(), index++);\n+\t\t\t \u0022%s: tid: %d, msg: %d\u0022, vhd-\u003econfig,\n+\t\t\t whoami, index++);\n \t\tamsg.len \u003d n;\n \t\tn \u003d lws_ring_insert(vhd-\u003ering, \u0026amsg, 1);\n \t\tif (n !\u003d 1) {\n@@ -127,7 +131,7 @@ wait:\n \n \t} while (!vhd-\u003efinished);\n \n-\tlwsl_notice(\u0022thread_spam %p exiting\u005cn\u0022, (void *)pthread_self());\n+\tlwsl_notice(\u0022thread_spam %d exiting\u005cn\u0022, whoami);\n \n \tpthread_exit(NULL);\n \n","s":{"c":1750637842,"u": 9900}} ],"g": 3623,"chitpc": 0,"ehitpc": 0,"indexed":0 , "ab": 0, "si": 0, "db":0, "di":0, "sat":0, "lfc": "7d0a"}