473,407 Members | 2,676 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,407 software developers and data experts.

The use of PyW32_BEGIN_ALLOW_THREADS and PyW32_END_ALLOW_THREADS

sam
The follllowing code lifted from Mark Hammond Pywin32 code shows and
example of calling the Windows Kernel32 GetTickCount(),using
PyW32_BEGIN_ALLOW_THREADS and PYW32_END_ALLOW_THREADS. My Code does not
use this,but uses SetThreadAffinityMask(GetCurrentThread(),1). My
questions are:

1) What is the difference?
2) What happens after I leave my function, to the previous threads that
I may have had running?
3) Should I be using the BEGIN/END ALLOW_THREADS?
/ @pymethod string|win32api|GetTickCount|Returns the number of
milliseconds since windows started.
static PyObject *
PyGetTickCount(PyObject * self, PyObject * args)
{
if (!PyArg_ParseTuple (args, ":PyGetTickCount"))
return NULL;
PyW32_BEGIN_ALLOW_THREADS
DWORD count = GetTickCount();
PyW32_END_ALLOW_THREADS

return Py_BuildValue("l",(long)count);
}

Now my code uses the Microsoft
"SetThreadAffinityMask(GetCurrentThread(),1)"
//
// PROGRAMMER: Samuel W. Schulenburg
// DATE: May 18,2006
//
// FUNCTION: double dMyClock()
//
// DESCRIPTION: This function will return the seconds since the system
was started
// as a double. If a call to QueryPerformanceFrequency()
returns a true
// then QueryPerformanceCounter() will be used else the
standard 'C'
// dMyClock() function will be used.
//
// PARAMETERS: None
//
// RETURN: double The seconds passed sense the system was started
//
double dMyClock()
{
double dLow;
double dHigh;

if(iPerformanceClocks == 1) // if the hardware supports the high
performance clock
{
SetThreadAffinityMask(GetCurrentThread(),1);
QueryPerformanceCounter(&liPerformanceCount);
dLow = (double)liPerformanceCount.LowPart;
dHigh = (double)(liPerformanceCount.HighPart)*(4294967296. 0);
return((dLow+dHigh)/dTicksPerSecond);
}
else // use the standard C clock function
return((double) (clock()/dTicksPerSecond));
}

May 19 '06 #1
0 771

This thread has been closed and replies have been disabled. Please start a new discussion.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.