nanogui: Multi threads with WIN32 API
Subject:
Re: [nanogui] Multi threads with WIN32 API
From:
"Greg Haerr" ####@####.####
Date:
21 Nov 2001 18:17:32 -0000
Message-Id: <00b001c172b8$99934900$3aba46a6@xmission.com>
: I have an application where I'll use the WIN32 GDI API. It will be
: multi-threaded, though. What I plan on doing is to restrict all microwindows
: to a single thread other than PostThreadMessage, to require that
: PostThreadMessage always be sent to
: thread 0 or the above mentioned thread,
: and to put locking mutexes in the GdRoutines in engine/devlist.c.
:
: Make sense? See any other gotchas? Is there a suggested mutex API?
: Can I just use the pthread mutex semantics and provide a default
: NULL implementation?
Sounds good. I would like to see the mutex macros be placed
probably somewhere like include/mwtypes.h, and be setup so that
a compile time option turns them on or not. The macros could likely
use the pthread semantics, and include a macro to declare (or
null-declare) the pthread mutex itself. For example:
#define DEFINE_MUTEX ...
#define MUTEX_LOCK(sem) ...
#define MUTEX_UNLOCK(sem) ...
You may have to restrict all of the GdXXX drawing entry points
as well, in engine/*.c, but this would be a great starting point for
getting Microwindows thread-safe.
Let me know if I can help, I think your method should work. You may
have to play with SendMessage so that it works sending messages to
another thread, that's a little more complicated. Also, the GetMessage
list may have to have a private threadID member and only get messages
for that thread, unless you want to duplicate Win32 thread semantics, and
return all messages for all process threads...
Regards,
Greg