JetBrains / lincheck

Framework for testing concurrent data structures
Mozilla Public License 2.0
572 stars 33 forks source link

Thread yield transformer implementation is slightly incorrect #132

Closed kkarnauk closed 1 year ago

kkarnauk commented 1 year ago

Version: 2.16 (and the previous ones, too)

Issue

As you can see in the implementation of ThreadYieldTransformer, in order to understand whether it should remove yield-call, it checkes owner. But it doesn't take into account that owner means the actual callee (not the concrete class which method will be called).

In Java it's possible to call static methods from base classes. So, if we have a derived thread instance and call its yield, then it will not be removed.

But, I'm not sure that it's a big problem, because I think that almost all users call exactly Thread.yield().

How to fix

We can easily check that owner extends Thread as it's done in RandomTransformer. ASAIU, it fixes the problem.

ndkoval commented 1 year ago

We will get rid of this optimization and remove ThreadYieldTransformer, it does not really help in practice.