PR# 19356 {THREAD}.terminated accessed by name from C side
Problem Report Summary
Submitter: gobobe
Category: EiffelThreads
Priority: Medium
Date: 2017/05/01
Class: Bug
Severity: Non-critical
Number: 19356
Release: 17.05
Confidential: No
Status: Closed
Responsible:
Environment: win
Synopsis: {THREAD}.terminated accessed by name from C side
Description
I think that there is something wrong in the implementation of Threads. In file eif_threads.c there are 3 locations where the value of the attribute {THREAD}.terminated is read or set. But this is done by name, using the string "terminated". I think that this will not work when a descendant of THREAD renames this attribute.
I would rather pass, as extra argument at the time of the creation of the thread, two feature pointers. One to a frozen getter of this attribute, and one to a frozen setter of this attribute, which could be added to class THREAD. That way, from the C code, we would call these getter and setter through their pointers instead of relying on names. This would also allow to protect (from the Eiffel side) the access to {THREAD}.terminated in these getter and setter with {THREAD}.launch_mutex.
--
Eric Bezault
To Reproduce
Problem Report Interactions
Closed this problem report.
Fixed in rev#100327.
See suggested fix at: https://github.com/EiffelSoftware/EiffelStudio/pull/14 -- Eric Bezault
Added test#thread025.
Here are some examples showing the problem.
Example1:
-------------
~~~~~~~~~~~~~~~~~~~~
class FOO
create
make
feature
make
local
l_thread: MY_THREAD
do
print ("Thread start%N")
create l_thread.make
l_thread.launch
l_thread.join
print ("Thread done%N")
end
end
~~~~~~~~~~~~~~~~~~~~
class MY_THREAD
inherit
THREAD
rename
terminated as thread_terminated
end
create
make
feature
execute
do
print ("Execute thread (start)%N")
(create {EXECUTION_ENVIRONMENT}).sleep (5000000000)
print ("Execute thread (done)%N")
end
end
~~~~~~~~~~~~~~~~~~~~
Output:
~~~~~~~~~~~~~~~~~~~~
Thread start
Execute thread (start)
Execute thread (done)
~~~~~~~~~~~~~~~~~~~~
The program never terminates.
Example2:
-------------
~~~~~~~~~~~~~~~~~~~~
class FOO
create
make
feature
make
local
l_thread: MY_THREAD
do
print ("Thread start%N")
create l_thread.make
l_thread.launch
l_thre
....
Output truncated, Click download to get the full message