I disagree with making the proposed change. Here is my reasoning:
The TLA+ spec models StartKeyGeneration(t)
and GenerateKeys(t)
as two distinct, atomic actions, where t
identifies the specific thread performing the action. The current implementation, following the guidelines in prompt.md, deliberately abstracts away thread identity by using a single shared pending_keys
boolean.
Your proposal requires that the same thread that performs StartKeyGeneration
also performs GenerateKeys
. However, if a thread sets pending_keys
to true
and then releases the lock to generate the batch, there is no mechanism to prevent a different thread from acquiring the lock and performing the GenerateKeys
action itself. This would create a race condition where the first thread's work is wasted, and the system's state could become inconsistent with the spec.
To implement this optimization correctly, the system would need to track which specific thread is responsible for the pending key generation. This would req