- Porting pthread_mutex and pthread_cond into Win32
- Posted by driver_folks on February 28th, 2008
I'm trying to implement the thread process from Linux into WinXP. Does anyone
know about the corresponding functionalities on Win32 similar to
pthread_mutex_init, pthread_mutex_lock, pthread_mutex_unlock,
pthread_cond_init, pthread_cond_wait, pthread_cond_signal, and pthread_join?
Thanks
- Posted by Maxim S. Shatskih on February 29th, 2008
There is no condvars in Windows and no chances of properly implementing
them, so sorry, you will need to rework all of your code working with condvars
to use events instead.
The difference is that event holds the state, it remembers whether it was
open or closed, while condvar does not, so, pthread_cond_signal is just plain a
no-op if there are no waiters. The similar SetEvent function is not such, it
will affect _future_ waiters if there is no current ones.
pthread_join is WaitForSingleObject on a thread handle
pthread_mutex_init/lock/unlock are Initialize/Enter/LeaveCriticalSection
--
Maxim Shatskih, Windows DDK MVP
StorageCraft Corporation
maxim@storagecraft.com
http://www.storagecraft.com
"driver_folks" <driverfolks@discussions.microsoft.com> wrote in message
news:3D76EDE4-B69A-451D-9AB6-6FCAA0CB7EFD@microsoft.com...
- Posted by Vladimir Petter [MSFT] on February 29th, 2008
Starting from Vista OS implements condition variable
http://msdn2.microsoft.com/en-us/library/ms682052.aspx
but on XP you are on your own.
Check out boost..org They somehow implement cv for windows.
Vladimir.
"Maxim S. Shatskih" <maxim@storagecraft.com> wrote in message
news:Og6Mz4oeIHA.6092@TK2MSFTNGP06.phx.gbl...
- Posted by Maxim S. Shatskih on February 29th, 2008
Yes, SignalObjectAndWait allows something similar, but this differ from the
classic UNIX condvar anyway.
--
Maxim Shatskih, Windows DDK MVP
StorageCraft Corporation
maxim@storagecraft.com
http://www.storagecraft.com
- Posted by driver_folks on February 29th, 2008
Thanks. Can CRITICAL_SECTION be used in XP kernel driver?
--
kc
"Maxim S. Shatskih" wrote:
- Posted by Doron Holan [MSFT] on February 29th, 2008
no. either use a KEVENT or KSPIN_LOCK depending on your IRQL requirements
d
--
Please do not send e-mail directly to this alias. this alias is for
newsgroup purposes only.
This posting is provided "AS IS" with no warranties, and confers no rights.
"driver_folks" <driverfolks@discussions.microsoft.com> wrote in message
news:F4F452F5-AA2D-4D99-8E60-19CC1348DDD5@microsoft.com...
- Posted by Maxim S. Shatskih on February 29th, 2008
Actually, I would say that the most popular lock for < DISPATCH_LEVEL is
FAST_MUTEX, which is probably the direct replacement of CRITICAL_SECTION for
the kernel.
Everybody must note, though, that FAST_MUTEX is NOT recursive, unlike
CRITICAL_SECTION.
(surely you, Doron, know this better then me, but the other forum
participants are possibly not)
--
Maxim Shatskih, Windows DDK MVP
StorageCraft Corporation
maxim@storagecraft.com
http://www.storagecraft.com
"Doron Holan [MSFT]" <doronh@online.microsoft.com> wrote in message
news:%23hYM$wveIHA.4376@TK2MSFTNGP05.phx.gbl...
- Posted by Doron Holan [MSFT] on February 29th, 2008
the thing with FAST_MUTEX is that it raises to APC_LEVEL, so if you want to
call functions who are only callable at PASSIVE_LEVEL, you are out of luck.
for instance, calling a ZwReadFile/WriteFile at apc_level can easily lead to
hang b/c the completion APC will never be dequeued.
d
--
Please do not send e-mail directly to this alias. this alias is for
newsgroup purposes only.
This posting is provided "AS IS" with no warranties, and confers no rights.
"Maxim S. Shatskih" <maxim@storagecraft.com> wrote in message
news:OuEA7fweIHA.4728@TK2MSFTNGP03.phx.gbl...
- Posted by Maxim S. Shatskih on March 1st, 2008
Calling complex functions under the lock is bad idea for sure.
--
Maxim Shatskih, Windows DDK MVP
StorageCraft Corporation
maxim@storagecraft.com
http://www.storagecraft.com
"Doron Holan [MSFT]" <doronh@online.microsoft.com> wrote in message
news:u3Sh91xeIHA.5620@TK2MSFTNGP04.phx.gbl...