Hi all,

I wrote some test code that was trying to drain a process::Queue. This ended up 
losing values from the queue, as demonstrated by:

TEST(QueueTest, Discard)
{
  Queue<int> q;

  Future<int> get = q.get();
  EXPECT_FALSE(get.isReady());

  get.discard();
  EXPECT_TRUE(get.hasDiscard());

  q.put(42);
  get = q.get();
  EXPECT_TRUE(get.isReady()); << fails because '42' is set on the discarded 
future
  EXPECT_EQ(42, get.get());
}

In process::Queue, I can detect Future::hadDiscard and then discard the 
associated Promise, but this suffers from a TTCTTOU race. It almost looks like 
the right way to deal with this is to just call Promise::set, which calls 
Future::set. The problem is that a Future does not move into DISCARDED state 
until its associated Promise is discarded. Is there a race-free way to know 
when you tried do set a value on a discarded Future?

thanks,
James

Reply via email to