Skip to content
Tcl Source Code Ticket Change Details
Login

Ticket Change Details

Overview

Artifact ID: ce2c4b8ed4ec25b5ebbbeda9ec401fdeda72fbe7
Ticket: 416643ffffffffffffffffffffffffffffffffff
rand() has identical results in threads.
User & Date: davygrvy on 2001-04-17 11:27:49
Changes

  1. assignee changed to: "nobody"
  2. cmimetype changed to: "text/plain"
  3. comment changed to:
    This is having difficulty on windows.  Isn't the c-
    runtime supposed to handle this situation just fine?  
    I'm perplexed by this:
    
    
    package require Thread
    
    foreach a {1 2 3 4 5 6} {
       set threads($a) [thread::create { proc doit {} { 
    puts [expr {rand()}] }; thread::wait }]
    }
    
    foreach a {1 2 3 4 5 6} {
       thread::send -async $threads($a) doit
    }
    
    foreach a {1 2 3 4 5 6} {
       thread::send -async $threads($a) thread::exit
    }
    
    
    C:\Program Files\Tcl\bin>tclsh84t
    % source test.tcl
    % 0.0541875106535
    0.0541875106535
    0.0541875106535
    0.0541875106535
    0.0541875106535
    0.0541875106535
    
    
    I really don't think this is a Tcl inherit to Tcl, but 
    does show an interesting behavior.  Changing the run 
    to be syncronous got this:
    
    package require Thread
    
    foreach a {1 2 3 4 5 6} {
       thread::create { puts [expr {rand()}] }
    }
    
    % source test.tcl
    0.11639496317
    0.366838779471
    0.366838779471
    0.484234318363
    0.609456226513
    % 0.726851765405
    
    
    The docs state "Each interpreter has it's own seed." 
    on the expr man page, but I tend to disagree after 
    seeing the above.  Where's the seeding happening?  
    Should Tcl_CreateInterp() do the seeding?
    
  4. foundin changed to: "obsolete: 8.4a2"
  5. priority changed to: "5 Medium"
  6. resolution changed to: "None"
  7. status changed to: "Open"
  8. submitter changed to: "davygrvy"
  9. subsystem changed to: "49. Threading"
  10. title changed to: "rand() has identical results in threads."
  11. type changed to: "Bug"