Fix race bug.
authorDavid Anderson <dvander@alliedmods.net>
Thu Aug 29 23:51:20 2013 -0700 (2013-08-29)
changeset 15245a69265bd5
parent 14 4ae6d413d3be
child 16 c513ef40773e
Fix race bug.
tests/test-threadutils.cpp
     1.1 --- a/tests/test-threadutils.cpp	Thu Aug 29 11:46:21 2013 -0700
     1.2 +++ b/tests/test-threadutils.cpp	Thu Aug 29 23:51:20 2013 -0700
     1.3 @@ -40,13 +40,15 @@
     1.4   public:
     1.5    TestWorkerModel()
     1.6     : terminate_(false),
     1.7 -     result_(0)
     1.8 +     result_(0),
     1.9 +     started_(false)
    1.10    {
    1.11    }
    1.12  
    1.13    void Run() {
    1.14      {
    1.15        AutoLock lock(main());
    1.16 +      started_ = true;
    1.17        main()->Notify();
    1.18      }
    1.19  
    1.20 @@ -87,6 +89,10 @@
    1.21      return result_;
    1.22    }
    1.23  
    1.24 +  bool started() {
    1.25 +    return started_;
    1.26 +  }
    1.27 +
    1.28    void send(int value) {
    1.29      AutoLock lock(&wakeup_);
    1.30      items_.append(value);
    1.31 @@ -99,6 +105,7 @@
    1.32    LinkedList<int> items_;
    1.33    bool terminate_;
    1.34    int result_;
    1.35 +  bool started_;
    1.36  };
    1.37  
    1.38  class TestThreading : public Test
    1.39 @@ -112,13 +119,14 @@
    1.40    bool testWorkerModel()
    1.41    {
    1.42      TestWorkerModel test;
    1.43 +
    1.44      ke::AutoPtr<Thread> thread(new Thread(&test, "TestWorkerModel"));
    1.45      if (!check(thread->Succeeded(), "thread launched"))
    1.46        return false;
    1.47  
    1.48      {
    1.49        AutoLock lock(test.main());
    1.50 -      if (!check(test.main()->Wait(5000) == Wait_Signaled, "thread started within five seconds"))
    1.51 +      if (!check(test.started() || test.main()->Wait(5000) == Wait_Signaled, "thread started within five seconds"))
    1.52          return false;
    1.53      }
    1.54