Artifacts Associated With Ticket 411603ffffffffff
Ticket change [523ddc910a] (rid 126280) by ruppert on 2001-03-27 10:49:31:
- assignee initialized to: "nobody"
- cmimetype initialized to: "text/plain"
- comment initialized to:
Hi, a collegue of mine has debugged a strange behaviour of a Tk script which was executed in a Tcl interpreter with threads enabled under Solaris 2.6. We observed that even trivial scripts which include an entry widget with a blinking cursor drive the cpu load to substantial values (up to 100% on smaller workstations, i.e. Sparcstation 5), as long as the cursor is blinking! This can be reproduced with the following trivial script: entry .entry -bg white -relief sunken pack .entry -side left -fill x -expand yes To reproduce: Execute these two lines in a wish which has been built with --enable-scripts, click into the entry widget (which makes the cursor start blinking) and observe the cpu load in a perfmeter. We could reproduce this with Tk versions 8.3.0, 8.3.2 and 8.4a2 on Solaris 2.6; a collegue reproduced this also on a Linux box. After some extensive debugging, the ultimate reason for this was found: a timeout value in Tcl_ConditionWait (tclUnixThrd.c) is computed in a way which is, for timeout values < 1sec, almost always incorrect: ------------------------------------------------------------------ void Tcl_ConditionWait(condPtr, mutexPtr, timePtr) Tcl_Condition *condPtr;/* Really (pthread_cond_t **) */ Tcl_Mutex *mutexPtr;/* Really (pthread_mutex_t **) */ Tcl_Time *timePtr;/* Timeout on waiting period */ { pthread_cond_t *pcondPtr; pthread_mutex_t *pmutexPtr; struct timespec ptime; if (*condPtr == NULL) { MASTER_LOCK; /* * Double check inside mutex to avoid race, * then initialize condition variable if necessary. */ if (*condPtr == NULL) { pcondPtr = (pthread_cond_t *)ckalloc(sizeof(pthread_cond_t)); pthread_cond_init(pcondPtr, NULL); *condPtr = (Tcl_Condition)pcondPtr; TclRememberCondition(condPtr); } MASTER_UNLOCK; } pmutexPtr = *((pthread_mutex_t **)mutexPtr); pcondPtr = *((pthread_cond_t **)condPtr); if (timePtr == NULL) { pthread_cond_wait(pcondPtr, pmutexPtr); } else { ptime.tv_sec = timePtr->sec + TclpGetSeconds(); <------ ptime.tv_nsec = 1000 * timePtr->usec; <------ pthread_cond_timedwait(pcondPtr, pmutexPtr, &ptime); } } --------------------------------------------------------------- Explanation: the lines marked with the arrows attempt to calculate a time value from a desired time interval (*timePtr), which is composed from seconds and microseconds, and the current time, which is obtained with TclpGetSeconds, thus completely ignoring fractions of a second. Assume a desired timeout value of 300 ms, which is the default value for cursor blinking, scrollbar repeat rates etc. in Tk: timePtr->sec is zero, and timePtr->usec is 300000. ptime.tv_sec (the desired "firing time" of pthread_cond_timedwait) will thus always be the "current" second value, and ptime.tv_nsec corresponds to 300 ms. Therefore, 70% of the time, pthread_cond_timedwait will return immediately. Because this code is invoked from a loop waiting for events in situations when a blinking cursor has to be updated, the function Tcl_ConditionWait almost never really waits, but instead executes more or less permanently, as long as the cursor is blinking, thus leading to the observed cpu load values. Suggested fix: the timeout value needs to correctly take into account the microsecond component of the current time, including possible overflow situations when microsecond values add up to > 1000000. We suggest to replace the above two lines with the following: Tcl_Time now; TclpGetTime(&now); ptime.tv_sec = timePtr->sec + now.sec + ( timePtr->usec + now.usec ) / 1000000; ptime.tv_nsec = 1000 * (( timePtr->usec + now.usec ) % 1000000); We have tried this fix, and this has removed the problem completely. Best Regards D.Ruppert RTS GmbH Schwieberdingen/Germany [email protected] - foundin initialized to: "None"
- priority initialized to: "5 Medium"
- resolution initialized to: "None"
- status initialized to: "Open"
- submitter initialized to: "ruppert"
- subsystem initialized to: "49. Threading"
- title initialized to: "timeout bug in tclUnixThrd.c"
- type initialized to: "Bug"
Ticket change [7b47e8305c] (rid 90493) by hobbs on 2001-03-28 08:03:59:
- assignee changed to: "hobbs"
- closedate changed to: "2001-03-28T01:03:59"
- closer changed to: "hobbs"
- icomment:
Logged In: YES user_id=72656 patched as noted for 8.4a2, see patch 411773.
- login: "hobbs"
- mimetype: "text/plain"
- status changed to: "Closed"
- username: "hobbs"
Ticket change [551b703031] (rid 94072) by hobbs on 2001-03-28 08:04:58:
- closedate changed to: "2001-03-28T01:04:58"
- closer changed to: "hobbs"
- icomment:
Logged In: YES user_id=72656 patched as noted for 8.4a2, see patch 411773.
- login: "hobbs"
- mimetype: "text/plain"
- username: "hobbs"
Ticket change [a5085bfad3] (rid 110305) by hobbs on 2001-03-28 08:13:04:
- closedate changed to: "2001-03-28T01:13:04"
- closer changed to: "hobbs"
- icomment:
Logged In: YES user_id=72656 patched as noted for 8.4a2, see patch 411773.
- login: "hobbs"
- mimetype: "text/plain"
- username: "hobbs"
Ticket change [8e085bbf17] (rid 120047) by hobbs on 2001-03-28 08:54:34:
- closedate changed to: "2001-03-28T01:54:34"
- closer changed to: "hobbs"
- icomment:
Logged In: YES user_id=72656 patched as noted for 8.4a2, see patch 411773.
- login: "hobbs"
- mimetype: "text/plain"
- username: "hobbs"
Ticket change [9dd320eb0e] (rid 96376) by dgp on 2001-03-30 04:53:21:
- closedate changed to: "2001-03-29T21:53:21"
- closer changed to: "dgp"
- resolution changed to: "Fixed"