[ python-Bugs-1484172 ] hyper-threading locks up sleeping threads
SourceForge.net
noreply at sourceforge.net
Mon May 8 23:45:48 CEST 2006
Bugs item #1484172, was opened at 2006-05-08 16:45
Message generated for change (Tracker Item Submitted) made by Item Submitter
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=1484172&group_id=5470
Please note that this message will contain a full copy of the comment thread,
including the initial issue submission, for this request,
not just the latest update.
Category: Threads
Group: Python 2.3
Status: Open
Resolution: None
Priority: 5
Submitted By: Olaf Meding (olafmeding)
Assigned to: Nobody/Anonymous (nobody)
Summary: hyper-threading locks up sleeping threads
Initial Comment:
Below are 2 files. The first is a Python program that
demonstrates the problem within less than 1 hour
(often just a few minutes). The second is a C++
program that shows that the Win32 Sleep() function
works as expected (the program was started 3 days ago
and is still running).
Note, I also attached the source code.
Note, the Python programs hangs (stops responding)
with hyper-threading turned on (a BIOS setting), but
works as expected with hyper-threading turned off.
This problem happens on Windows only (the below Python
program ran for 24 hours on Linux without a problem).
Variations of the Python program also lock up:
Tried importing win32api instead of importing time and
using the win32api.GetTickCount() and win32api.Sleep()
methods.
Tried using lock = threading.Event() and lock.wait()
instead of time.sleep().
Tried importing Queue and using q = Queue.Queue() and
q.get(True, sleepTime).
Note, the Windows task manager shows 2 CPUs on the
Performance tab with hyper-threading is turned on.
Both Python 2.3.5 and 2.4.3 (downloaded from
python.org) have this problem.
The operating system is MS Windows XP Professional.
winmsd.exe (Start Menu > Run) shows:
2CPUs: x86 Family 15 Model 4 Stepping 1 GenuineIntel
~3000 MHz
Version: 5.1.2600 Service Pack 2 Build 2600
Could someone with a hyper-threading (or dual-core or
multi-processor) CPU please confirm this bug?
Many Thanks
Olaf
Here is the expected output of both programs (the
progam has locked up if the numbers stop printing
every 10 seconds or so):
python testsleep.py
thread 1 started, sleep time 0.010
thread 2 started, sleep time 0.003
1 1 1 2 1 1 1 2 1 1 1 2 1 1 1 1 2 1 1 1
# testsleep.py
import threading
import time
class Task(threading.Thread):
def __init__(self, n, t):
threading.Thread.__init__(self)
self.n = n # thread id
self.t = t # sleep time
def run(self):
print 'thread %d started, sleep time
%.3f' % (self.n, self.t)
count = 0
printCount = int(10 / self.t)
while True:
start = time.clock()
time.sleep(self.t)
stop = time.clock()
if stop - start > 1.0:
print 'thread',
self.n, stop - start
count += 1
if count > printCount:
count = 0
print self.n, # print
sign of live
def test():
thread1 = Task(1, 0.01) # thread 1, sleep 10
ms
thread2 = Task(2, 0.003) # thread 2, sleep 3
ms
thread1.start()
thread2.start()
test()
-------------------------------------------------------
---------------------------
// testsleep.cpp
// Compiled with Visual C++ version 6 (in debug mode)
as a Win32 console application.
#include <windows.h>
#include <stdio.h>
#include <time.h>
typedef struct {
int id;
int ms;
} param_s;
DWORD WINAPI threadFunction(LPVOID param)
{
param_s* p = (param_s*)param;
long elapsedTime;
long time1, time2;
long printCount = long(10000 / p->ms); // loop
iterations in 10 seconds
long count = 0;
printf("thread %d started, sleep time: %d
ms" "\n", p->id, p->ms);
while(true) {
time1 = GetTickCount();
Sleep(p->ms);
time2 = GetTickCount();
elapsedTime = time2 - time1;
if(elapsedTime > 1000)
printf("thread %d slept for %d ms" "\n", p-
>id, elapsedTime);
count++;
if(count > printCount) {
count = 0;
printf("%d ", p->id); // print sign of
live
}
}
return 0;
}
int main(int argc, char* argv[])
{
param_s p1, p2;
p1.id = 1;
p1.ms = 10;
p2.id = 2;
p2.ms = 3;
CreateThread(NULL, 0, threadFunction, (void*)&p1,
0, NULL);
CreateThread(NULL, 0, threadFunction, (void*)&p2,
0, NULL);
getchar(); // wait until the user presses the
enter key.
return 0;
}
----------------------------------------------------------------------
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=1484172&group_id=5470
More information about the Python-bugs-list
mailing list