Skip to content
Tcl Source Code Ticket Change Details
Login

Ticket Change Details

Overview

Artifact ID: a181ce9cd0200fea49b73e60099b1add600389e0317b7efabdca938b3a1f4953
Ticket: 36f6f784370384e866939d56e6c35f57473b8b77
"package require" is not thread-safe
User & Date: tomkiti on 2025-08-12 19:48:35
Changes

  1. assignee changed to: "nobody"
  2. closer changed to: "nobody"
  3. cmimetype changed to: "text/x-fossil-plain"
  4. comment changed to:
    The "package require" command fails on Windows when loading the same package in multiple threads simultaneously:
    
        package require Thread
    
        set numThreads 100
        for {set i 0} {$i < $numThreads} {incr i} {
            set id [::thread::create]
            ::thread::send -async $id "package require itcl"
            #after 100 ;# uncomment to pass
        }
    
    One possible result is:
    
        Error from thread tid0000000000009d6c
        can't find package itcl
            while executing
        "package require itcl"
        Error from thread tid0000000000001dc8
        can't find package itcl
            while executing
        "package require itcl"
        Error from thread tid0000000000002c48
        can't find package itcl
            while executing
        "package require itcl"
        Error from thread tid000000000000af44
        can't find package itcl
            while executing
        "package require itcl"
    
    The exact number of errors varies and depends on the speed of the computer and the number of threads spawned. The error does not occur on Linux or in Tcl 8.6.16. The workaround is to add a slight delay between commands, e.g. the "after" command above. The exact delay also depends on the speed of the computer and the number of threads spawned. This can significantly slow down startup time when spawning a large number of threads and does not guarantee that the error will not occur later.
    
  5. foundin changed to: "9.0.2"
  6. is_private changed to: "0"
  7. login: "tomkiti"
  8. priority changed to: "5 Medium"
  9. private_contact changed to: "1c57e67924247fd7926e89348f266c081ec57db2"
  10. resolution changed to: "None"
  11. severity changed to: "Important"
  12. status changed to: "Open"
  13. submitter changed to: "tomkiti"
  14. subsystem changed to: "39. Package Manager"
  15. title changed to: ""package require" is not thread-safe"
  16. type changed to: "Bug"