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

[PATCH] Windows: a minimal pthread_cond_broadcast

From
Johannes Sixt <j6t@kdbg.org>
Date
Jan 29, 2010, 22:16 UTC
Message-ID
<201001292316.03858.j6t@kdbg.org>
In-Reply-To
<201001292102.49105.j6t@kdbg.org>
[Cc msysgit list]
On Freitag, 29. Januar 2010, Johannes Sixt wrote:
> cond_broadcast is not that trivial.

... except when it can be tailor-made for a particular use-case. What do people think about this?

I had implemented a full-blown pthread_cond_broadcast, taking ACE as an example, but I had doubts about its correctness. Then I noticed that we do not need a complete implementation anyway. So here we go...

--- 8< ---
From: Johannes Sixt <j6t@kdbg.org>
Subject: [PATCH] Windows: a minimal pthread_cond_broadcast

This is not an implementation, but more a fake of pthread_cond_broadcast. It is sufficient for the only call site in builtin-grep.c that we have at this time. It works because the threads that wake up due to this call do not call pthread_cond_wait anymore and terminate.

Signed-off-by: Johannes Sixt <j6t@kdbg.org>
---
 compat/win32/pthread.c |   10 ++++++++++
 compat/win32/pthread.h |    4 +---
 2 files changed, 11 insertions(+), 3 deletions(-)
diff --git a/compat/win32/pthread.c b/compat/win32/pthread.c
index 631c0a4..7b5cac1 100644
--- a/compat/win32/pthread.c
+++ b/compat/win32/pthread.c
@@ -108,3 +108,13 @@ int pthread_cond_signal(pthread_cond_t *cond)
 	else
 		return 0;
 }
+
+/*
+ * FIXME: This is a fake implementation that is tailored for the only
+ * user that we currently have.
+ */
+int pthread_cond_broadcast(pthread_cond_t *cond)
+{
+	ReleaseSemaphore(cond->sema, cond->waiters, NULL);
+	return 0;
+}
diff --git a/compat/win32/pthread.h b/compat/win32/pthread.h
index b8e1bcb..7c360d5 100644
--- a/compat/win32/pthread.h
+++ b/compat/win32/pthread.h
@@ -37,12 +37,10 @@ typedef struct {
 } pthread_cond_t;
 
 extern int pthread_cond_init(pthread_cond_t *cond, const void *unused);
-
 extern int pthread_cond_destroy(pthread_cond_t *cond);
-
 extern int pthread_cond_wait(pthread_cond_t *cond, CRITICAL_SECTION *mutex);
-
 extern int pthread_cond_signal(pthread_cond_t *cond);
+extern int pthread_cond_broadcast(pthread_cond_t *cond);
 
 /*
  * Simple thread creation implementation using pthread API
-- 
1.6.6.264.ga6155
Previous: Johannes SixtNext: Johannes Sixt
Message 5 of 10 in “threaded-grep cause msys build failure”
  1. Zoltán FüzesiJan 29, 2010
  2. Johannes SixtJan 29, 2010
  3. MSVC: Windows-native implementation of pthread_cond_broadcastZoltán Füzesi, Jan 29, 2010
  4. Johannes SixtJan 29, 2010
  5. Windows: a minimal pthread_cond_broadcastJohannes Sixt, Jan 29, 2010
  6. Implement pthread_cond_broadcast on WindowsJohannes Sixt, Jan 29, 2010
  7. Johannes SchindelinJan 30, 2010
  8. Johannes SixtJan 30, 2010
  9. Johannes SchindelinJan 30, 2010
  10. Johannes SchindelinJan 29, 2010

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.