Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
7899acfc
Commit
7899acfc
authored
Mar 31, 2011
by
Antoine Pitrou
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Issue #11618: Fix the timeout logic in threading.Lock.acquire() under
Windows.
parent
8c5b7480
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
20 additions
and
59 deletions
+20
-59
Lib/test/lock_tests.py
Lib/test/lock_tests.py
+10
-0
Misc/NEWS
Misc/NEWS
+2
-0
Python/thread_nt.h
Python/thread_nt.h
+8
-59
No files found.
Lib/test/lock_tests.py
View file @
7899acfc
...
...
@@ -213,6 +213,16 @@ class LockTests(BaseLockTests):
lock
.
acquire
()
lock
.
release
()
def
test_state_after_timeout
(
self
):
# Issue #11618: check that lock is in a proper state after a
# (non-zero) timeout.
lock
=
self
.
locktype
()
lock
.
acquire
()
self
.
assertFalse
(
lock
.
acquire
(
timeout
=
0.01
))
lock
.
release
()
self
.
assertFalse
(
lock
.
locked
())
self
.
assertTrue
(
lock
.
acquire
(
blocking
=
False
))
class
RLockTests
(
BaseLockTests
):
"""
...
...
Misc/NEWS
View file @
7899acfc
...
...
@@ -49,6 +49,8 @@ Core and Builtins
Library
-------
-
Issue
#
11618
:
Fix
the
timeout
logic
in
threading
.
Lock
.
acquire
()
under
Windows
.
-
Issue
#
11256
:
Fix
inspect
.
getcallargs
on
functions
that
take
only
keyword
arguments
.
...
...
Python/thread_nt.h
View file @
7899acfc
...
...
@@ -9,82 +9,31 @@
#include <process.h>
#endif
typedef
struct
NRMUTEX
{
LONG
owned
;
DWORD
thread_id
;
HANDLE
hevent
;
}
NRMUTEX
,
*
PNRMUTEX
;
#define PNRMUTEX HANDLE
BOOL
InitializeNonRecursiveMutex
(
PNRMUTEX
mutex
)
PNRMUTEX
AllocNonRecursiveMutex
()
{
mutex
->
owned
=
-
1
;
/* No threads have entered NonRecursiveMutex */
mutex
->
thread_id
=
0
;
mutex
->
hevent
=
CreateEvent
(
NULL
,
FALSE
,
FALSE
,
NULL
)
;
return
mutex
->
hevent
!=
NULL
;
/* TRUE if the mutex is created */
return
CreateSemaphore
(
NULL
,
1
,
1
,
NULL
);
}
VOID
Delet
eNonRecursiveMutex
(
PNRMUTEX
mutex
)
Fre
eNonRecursiveMutex
(
PNRMUTEX
mutex
)
{
/* No in-use check */
CloseHandle
(
mutex
->
hevent
)
;
mutex
->
hevent
=
NULL
;
/* Just in case */
CloseHandle
(
mutex
);
}
DWORD
EnterNonRecursiveMutex
(
PNRMUTEX
mutex
,
DWORD
milliseconds
)
{
/* Assume that the thread waits successfully */
DWORD
ret
;
/* InterlockedIncrement(&mutex->owned) == 0 means that no thread currently owns the mutex */
if
(
milliseconds
==
0
)
{
if
(
InterlockedCompareExchange
(
&
mutex
->
owned
,
0
,
-
1
)
!=
-
1
)
return
WAIT_TIMEOUT
;
ret
=
WAIT_OBJECT_0
;
}
else
ret
=
InterlockedIncrement
(
&
mutex
->
owned
)
?
/* Some thread owns the mutex, let's wait... */
WaitForSingleObject
(
mutex
->
hevent
,
milliseconds
)
:
WAIT_OBJECT_0
;
mutex
->
thread_id
=
GetCurrentThreadId
()
;
/* We own it */
return
ret
;
return
WaitForSingleObject
(
mutex
,
milliseconds
);
}
BOOL
LeaveNonRecursiveMutex
(
PNRMUTEX
mutex
)
{
/* We don't own the mutex */
mutex
->
thread_id
=
0
;
return
InterlockedDecrement
(
&
mutex
->
owned
)
<
0
||
SetEvent
(
mutex
->
hevent
)
;
/* Other threads are waiting, wake one on them up */
}
PNRMUTEX
AllocNonRecursiveMutex
(
void
)
{
PNRMUTEX
mutex
=
(
PNRMUTEX
)
malloc
(
sizeof
(
NRMUTEX
))
;
if
(
mutex
&&
!
InitializeNonRecursiveMutex
(
mutex
))
{
free
(
mutex
)
;
mutex
=
NULL
;
}
return
mutex
;
}
void
FreeNonRecursiveMutex
(
PNRMUTEX
mutex
)
{
if
(
mutex
)
{
DeleteNonRecursiveMutex
(
mutex
)
;
free
(
mutex
)
;
}
return
ReleaseSemaphore
(
mutex
,
1
,
NULL
);
}
long
PyThread_get_thread_ident
(
void
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment