Open 64kramsystem opened 6 years ago
Um...I don't think it'd be a test framework issue, should be something wrong in the interpreter.
It seems that the race condition is caused by assigning the string object "thread"
to the finish_message
pointer's value, while we're reading that pointer's value after evaluating a call frame for checking error objects.
I think the best solution is to change the way we do error checking, I'll try to fix this in this week.
@saveriomiroddi I think I might need your help on this. We sometimes might have race condition on pointer's target read/assignment. In current implementation this might happen when we assign values to the var finish_message
at thread A
, and checking if the top pointer (which is also var finish_message
)'s value is an error at thread B
. I'm not familiar with the pointer's thread safety, should we also need to implement something like share_ptr
in c++
?
BTW if we just put a fmt.Println("123")
inside thread
's execInstruction
function then everything will work fine, I don't know why
Very interesting. I'll review this over the next few days!
Hello! This is a very interesting subject. As a general observation, I think this is the typical reasons why scripting interpreters use the GIL :smile:
Having said that, I had a cursory look around at the general patterns for handling shared access to pointers (which are not thread safe in Go).
I think that the high level behavior of the code would reflect the low-level one (note that I didn't read the source code yet) - in other words, at high level, there is a shared access to a variable, at low level, to a pointer.
If this is the case, there are two options:
sync.Once
, which includes the boilerplate for variables shared access; this works as expected, but is in general discouraged in GoNot knowing Go well, and maybe, considering it as easier solution, I'd use 1.
@saveriomiroddi Actually after thinking for a few days, I think this case is acceptable. Yes, it might have a race condition on pointer's target, but that's what users should expect when writing such code. And the error is raised because the potential race condition is detected, not because there's something went wrong. So I suggest we should have a different place to put all the thread-related tests, and not running race condition check on them. What do you think?
If you're completely sure that writing this code won't case the executable to panic (which is undesirable, even for broken code) due to pointers undefined behavior, then that's a solution to the problem.
We can start writing the thread-related tests and I guess we'll find out then. But does this mean your mutex lock feature will be blocked?
We can start writing the thread-related tests and I guess we'll find out then. But does this mean your mutex lock feature will be blocked?
I will check it!
I've changed the title and description, since the race condition is not related to the test environment.
Observed in #493:
When concurrently access a variable, with the race detector, a race condition is detected.
I don't think that race conditions in the interpreted language should reflect in race conditions in the VM, although I'm not entirely sure without a good knowledge of the VM.
Test case: