Overview
| Artifact ID: | 07b2786dc6490bf7f2ef7aeae7e49a280fc6bcccf18bd32f9ea87b318605f5d3 |
|---|---|
| Ticket: | 893f8cc5db3ba8bd6bed80ce89a0a75c6088a37c
Nested mutexes following TIP 509 |
| User & Date: | sebres on 2025-09-17 12:18:10 |
Changes
- icomment:
<blockquote>> In the mean time, I saw sebres' branch (sebres--non-reentrant-mutex)...</blockquote> Although my own preference is to use non-reentrant mutexes further (neither see the necessity for TIP#509, nor I think it is good idea at all), but this branch was made for Schelte, to test his strange issue with 9.0, where in opposite to 8.6, the CPU load (and eval times) grows with the time and new findings are - tracing with bpftrace shows that mutexes may be responsible for that. Here is a quote from tcl-chat: <i style="display:block; padding-left:10pt;"><schelte> I finally managed to get some data that may be useful regarding the cpu usage increasing on Tcl 9: After the application has been running for 3 weeks, calls to Tcl_MutexLock() take 70% longer than just after the application is started. <schelte> Tcl_GetIndexFromObjStruct() increased by 20%. But Tcl_MutexLock() shows the biggest difference. </i> My assumption - since the unix mutexes use common alloc, and change the memory (lock counter, locked thread) in the block that may be shared across threads (potentially with other memory, if it is not aligned to CPU cache granularity), so we probably end up with something like [3d1c409f1a] after potential defragmentation. To test this, I provided a small patch for his 9.0, reverting reentrant mutexes, but it'd not work anymore after apn's encoding fix [0433b67adc5fb0b9], what expects reentrant mutexes now and would cause a deadlock by setting of system encoding. Therefore, the branch in case Schelte would need it for newer versions as well. That's it. P.S. Basic system functions such as mutexes are not for naive attempts at improvement and definitely require deeper knowledge of the subject matter. Unfortunately I didn't see the TIP at that time point, otherwise I had definitely express my doubts about it.<br/> Regarding the reentrant mutexes - someone, who may need it, doesn't understand the primary essential prerequisite of locking mechanisms - the lock shall be as short as possible. From this point of view - recursive usage of them is totally absurd. Moreover it'd quasi encourage the devs to write "bad" code.
- login: "sebres"
- mimetype: "text/x-fossil-wiki"