|
2019-05-06
| ||
| 13:37 | • Ticket [d82a78ebf2] Clarify execution order for thread creation scripts stat... artifact: 418c55840c user: elfring | |
| 13:00 | • Ticket [d82a78ebf2]: 5 changes artifact: 0e8842c5a3 user: elfring | |
| 12:11 | • Closed ticket [d82a78ebf2]. artifact: 61c4992dd5 user: sebres | |
|
2019-05-05
| ||
| 14:45 | • New ticket [d82a78ebf2]. artifact: afb7e6cf50 user: elfring | |
Clarify execution order for thread creation scripts
I have tried the following small script out for the software “TCL 8.6.9-1.5” on an openSUSE system.
package require Thread
puts {Thread creation}
set id [thread::create {
puts "The thread [thread::id] will sleep for a moment."
after 1200
puts "The thread [thread::id] is waiting for work."
thread::wait
}]
puts "Additional thread ($id) was created."
puts {The main thread will sleep for a moment.}
after 1230
puts {End of test case}
Test result:
elfring@Sonne:~/Projekte/TCL> tclsh test-thread1.tcl
Thread creation
The thread tid0x7fadfc763700 will sleep for a moment.
Additional thread (tid0x7fadfc763700) was created.
The main thread will sleep for a moment.
The thread tid0x7fadfc763700 is waiting for work.
End of test case
I got the impression from such test output that the main thread is informed about the identification for the additional thread before the preparation script of this extra thread was finished.
I find such software behaviour questionable in comparison to the provided documentation.
https://www.tcl.tk/man/tcl/ThreadCmd/thread.htm#M6
I interpreted the information from the thread package manual in the way for a while that it would be possible to let the calling thread to continue with its work only after successful initialisation of a related task.
There are some data processing consequences to consider if you can not depend on a known execution order there.
How would you like to clarify this situation?
Again, please use thread-repository for concerns of thread-package.
BTW, which sentence in the documentation exactly you interpret as "let the calling thread to continue with its work only after successful initialisation of a related task"?
I don't see something similar in the docu and in my opinion it was never the case in thread package...
The caller thread gets an id of main thread immediately after its interpreter got created (ready)...
However, if you want behavior like this, use constructs with synchronous thread::send like here:
set id [thread::create]; \
thread::send $id {
puts "thread [thread::id] creating..."; flush stdout
after 1200
puts "thread [thread::id] created."; flush stdout
}; \
puts "MAIN: we have created $id"; flush stdout
My interpretation of the documentation was influenced by the detail that it was not explicitly mentioned at which point the concurrent execution will be started for threads which are created by this programming interface.
See also: https://core.tcl-lang.org/thread/tktview/f5a5c23f47bef3d709e85c7d1f5883e473b8125b