Race Condition in Experimental.Threading.Future<T>

I know the Experimental.Threading.Future class is, as the name suggest, in experimental state. But when reading through the code I saw a race condition in InternalReject and InternalResolve:

protected void InternalResolve(T result)
{
    if (State != FutureState.Pending)
        throw new Exception();

    _mutex.Lock();
    State = FutureState.Resolved;
    ...

It should be:

_mutex.Lock();
if (State != FutureState.Pending)
{
    _mutex.Unlock();
    throw new Exception();
}

State = FutureState.Resolved;
...

Thanks for reporting, we are reviewing the Future and Promise implementations, will get this fixed :slight_smile:

Fix will be out in next release :slight_smile: