FXMutex difference between linux and win32

View: New views
3 Messages — Rating Filter:   Alert me  

FXMutex difference between linux and win32

by matheus ribeiro :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

It seems FoxTK Mutex behaves different on windows and linux. Im using version 1.6.35 of foxtk.

Windows mutex seems to be recursive mutex no matter what, i.e., the same thread can lock it multiple times. On Linux, mutex respects the construtor argument.

Heres Linux initialization:

[code]
  pthread_mutexattr_init(&mutexatt);
 phread_mutexattr_settype(&mutexatt,recursive?PTHREAD_MUTEX_RECURSIVE:PTHREAD_MUTEX_DEFAULT);
  pthread_mutex_init((pthread_mutex_t*)data,&mutexatt);
  pthread_mutexattr_destroy(&mutexatt);
[/code]

Now, heres Windows:

[code]
EnterCriticalSection((CRITICAL_SECTION*)data);
[/code]

MSDN (http://msdn.microsoft.com/en-us/library/ms682608(VS.85).aspx) says "After a thread has ownership of a critical section, it can make additional calls to EnterCriticalSection or TryEnterCriticalSection without blocking its execution" which means windows mutexes are always recursive.

Would be nice to have this either documented or fixed, though I suspect fixing this for windows isnt a simple matter since it doesnt offer a flexible API.

Thx
Matheus

------------------------------------------------------------------------------
Come build with us! The BlackBerry(R) Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay
ahead of the curve. Join us from November 9 - 12, 2009. Register now!
http://p.sf.net/sfu/devconference
_______________________________________________
Foxgui-users mailing list
Foxgui-users@...
https://lists.sourceforge.net/lists/listinfo/foxgui-users

Re: FXMutex difference between linux and win32

by Jeroen van der Zijp-5 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On Wednesday 28 October 2009, Matheus Ribeiro wrote:
> It seems FoxTK Mutex behaves different on windows and linux. Im using
> version 1.6.35 of foxtk.
>
> Windows mutex seems to be recursive mutex no matter what, i.e., the same
> thread can lock it multiple times. On Linux, mutex respects the construtor
> argument.

Correct..

> Heres Linux initialization:
>
> [code]
>   pthread_mutexattr_init(&mutexatt);
>  phread_mutexattr_settype(&mutexatt,recursive?PTHREAD_MUTEX_RECURSIVE:PTHREAD_MUTEX_DEFAULT);
>   pthread_mutex_init((pthread_mutex_t*)data,&mutexatt);
>   pthread_mutexattr_destroy(&mutexatt);
> [/code]
>
> Now, heres Windows:
>
> [code]
> EnterCriticalSection((CRITICAL_SECTION*)data);
> [/code]
>
> MSDN (http://msdn.microsoft.com/en-us/library/ms682608(VS.85).aspx) says
> "After a thread has ownership of a critical section, it can make additional
> calls to *EnterCriticalSection* or *TryEnterCriticalSection* without
> blocking its execution" which means windows mutexes are always recursive.
>
> Would be nice to have this either documented or fixed, though I suspect
> fixing this for windows isnt a simple matter since it doesnt offer a
> flexible API.

It can not be fixed, since Windows doesn't offer a non-recursive version.
Fortunately, using a recursive mutex instead of a non-recursive one is
almost always OK.  Vice-versa is not, however.  

Programs which erroneously use a non-recursive mutex as if it were recursive
would work on Windows, but lock-up on Linux.  

Of course, such programs would be incorrectly locking the mutex twice.

Since the internal structure of CRITICAL_SECTION is not known (in fact,
I've read in places that its been changed by Microsoft on occasion) its
not easily checked for multiple EnterCriticalSection() invocations to
trap this off.

OTOH, I don't feel I should slow correct programs down by trapping off
incorrect usage from misbehaving programs, esp. when there is no problem
for correctly behaving programs.

I do think the documentation should probably emphasize the need to pass
recursive=true when re-enterant mutexes are desired.


                - Jeroen



                - Jeroen


--
+----------------------------------------------------------------------------+
| Copyright (C) 18:40 10/28/2009 Jeroen van der Zijp.   All Rights Reserved. |
+----------------------------------------------------------------------------+

------------------------------------------------------------------------------
Come build with us! The BlackBerry(R) Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay
ahead of the curve. Join us from November 9 - 12, 2009. Register now!
http://p.sf.net/sfu/devconference
_______________________________________________
Foxgui-users mailing list
Foxgui-users@...
https://lists.sourceforge.net/lists/listinfo/foxgui-users

Re: FXMutex difference between linux and win32

by matheus ribeiro :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

I do think the documentation should probably emphasize the need to pass
recursive=true when re-enterant mutexes are desired.

Yes. Would be nice to have the documentation say the argument doesnt work on windows, since its mutexes are always recursive.

------------------------------------------------------------------------------
Come build with us! The BlackBerry(R) Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay
ahead of the curve. Join us from November 9 - 12, 2009. Register now!
http://p.sf.net/sfu/devconference
_______________________________________________
Foxgui-users mailing list
Foxgui-users@...
https://lists.sourceforge.net/lists/listinfo/foxgui-users