[Patches] [ python-Patches-500447 ] native win32 threading primitives

noreply@sourceforge.net noreply@sourceforge.net
Fri, 22 Nov 2002 00:44:56 -0800


Patches item #500447, was opened at 2002-01-07 17:34
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=305470&aid=500447&group_id=5470

Category: Modules
Group: None
Status: Open
Resolution: None
Priority: 5
Submitted By: Jason Orendorff (jorend)
Assigned to: Nobody/Anonymous (nobody)
Summary: native win32 threading primitives

Initial Comment:
The "threading" module provides five synchronization
primitives: Lock, RLock, Condition, Semaphore, and
Event.

This patch is a module, "winthreading", that provides
native C implementations (using Win32 directly) of
these objects.  Benchmark code runs several times
to several hundred times faster using winthreading.

winthreading.c is intended as a drop-in replacement
for these five pieces of threading.py:

  # At the end of threading.py; replace
  # Python synch primitives with native version,
  # if available.
  try:
      from winthreading import *
  except ImportError:
      pass


The ZIP file attached includes source and MSVC6
project files.  The source is compatible with
Python 2.2.

A prebuilt .PYD will follow.

----------------------------------------------------------------------

>Comment By: Martin v. Löwis (loewis)
Date: 2002-11-22 09:44

Message:
Logged In: YES 
user_id=21627

Jason, in this form, the patch is not acceptable. First of
all, it is no patch, and it doesn't integrate with the rest
of Python's threading libraries.

This is all fine if you want to distribute this as a
separate package (which I would encourage you to do).

If you want to have this become part of Python, you need to:
- modify the builtin thread module to expose your primitives,
- modify the threading module to use these primitives if
possible,
- provide documentation for these new functions
- possible provide support for these primitives for other
threading libraries (this is optional if your documentation
points out that these primitives are available only on windows).

Please let us know how you would like to proceed with this.

----------------------------------------------------------------------

Comment By: Jason Orendorff (jorend)
Date: 2002-01-08 07:49

Message:
Logged In: YES 
user_id=18139

Better source distribution attached.

----------------------------------------------------------------------

Comment By: Jason Orendorff (jorend)
Date: 2002-01-07 18:20

Message:
Logged In: YES 
user_id=18139

Test cases attached.

To run them, put winthreading.pyd in your PYTHONPATH
and run (for example)

 python test_rlock.py

Each test takes a few seconds to a minute to run
on my box; there's a lot of mysterious output,
followed by:

  threading: [2.5829999446868896, ...]
  average: 2.62159998417
  winthreading: [0.12999999523162842, ...]
  average: 0.122199988365
  performance gain: 95.339%
  winthreading is 21.5 times faster!

If you are brave, try modifying test_condition_2.py
a bit.  Change access.wait() to access.wait(50000)
on lines 25 and 39; and see what happens.  (If you
are not quite that brave, you might want to adjust
nloops, on line 46, down to about 500.)


----------------------------------------------------------------------

Comment By: Jason Orendorff (jorend)
Date: 2002-01-07 17:37

Message:
Logged In: YES 
user_id=18139

Prebuilt .PYD file, as promised.

----------------------------------------------------------------------

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=305470&aid=500447&group_id=5470