semaphores and Rlocks
James J. Besemer
jb at cascade-sys.com
Fri Dec 20 05:54:22 EST 2002
Jive Dadson wrote:
> Can someone tell me how semaphores and rlocks are implemented under Win32?
> I would expect them to be simple wrappers around MS Windows semaphore and
> critical section thingymadoodles,
Since they work on windows, unix and elsewhere, I would expect them to
be stand-alone implementations, unrelated to underlying OS functionality.
In fact, if you look in the python library (C:/python2.2/lib -- the place to
look for the source code for MOST "import" libraries) you'll find the source
code for threading.py. In it you see they're all just ordinary Python
objects, which rely on Python's synchronization primitive, "locks" from the
thread built-in module.
All the thread and threading synchronization ops are defined to work only in
terms of python threads, which in turn may or may not use the native OS
threads. The threading functions all work just fine for Python and have the
added advantage that they work portably on multiple OS's.
The down side is that they are NOT (necessarily) directly related to the
corresponding OS functions. Thus, say, if you have the rare need to
synchronize your Python PROCESS on Windows with some other windows PROCESS,
then Python's threading functions won't do the trick.
Exercise for the student (if you do truly need Win's ops): in the Windows
version of Python there are separate "windows" libraries which interface more
directly to low-level OS APIs. Stepping off point is
C:/python2.2/lib/site-packages. win32 exports most "win32" APIs. Can't
recall if windows synchronization primitives are in there or not. Should be
easy for you to find out.
There's also win32com and win32comext for win COM and win COM Extensions.
PyWin32.hlp has documentation for much of APIs, though it may not be 100%.
If this is non-responsive and you really and truly want to know how the
python native threading and locking is IMPLEMENTED, I'll defer to somebody
else to point you to the source code.
--jb
--
James J. Besemer 503-280-0838 voice
2727 NE Skidmore St. 503-280-0375 fax
Portland, Oregon 97211-6557 mailto:jb at cascade-sys.com
http://cascade-sys.com
More information about the Python-list
mailing list