HookListMaxValues));
  EXPECT_EQ(69, values[0]);
  for (int i = 1; i < kHookListMaxValues; ++i) {
    EXPECT_EQ(i, values[i]);
  }
}

void MultithreadedTestThread(TestHookList* list, int shift,
                             int thread_num) {
  string message;
  char buf[64];
  for (int i = 1; i < 1000; ++i) {
    // In each loop, we insert a unique value, check it exists, remove it, and
    // check it doesn't exist.  We also record some stats to log at the end of
    // each thread.  Each insertion location and the length of the list is
    // non-deterministic (except for the very first one, over all threads, and
    // after the very last one the list should be empty).
    int value = (i << shift) + thread_num;
    EXPECT_TRUE(TestHookList_Add(list, value));
    sched_yield();  // Ensure some more interleaving.
    uintptr_t values[kHookListMaxValues + 1];
    int num_values = TestHookList_Traverse(*list, values, kHookListMaxValues);
    EXPECT_LT(0, num_values);
    int value_index;
    for (value_index = 0;
         value_index < num_values && values[value_index]!= value;
         ++value_index)
      ;
    EXPECT_LT(value_index, num_values);  // Should have found value.
    snprintf(buf, sizeof(buf), "[%d/%d; ", value_index, num_values);
    message += buf;
    sched_yield();
    EXPECT_TRUE(TestHookList_Remove(list, value));
    sched_yield();
    num_values = TestHookList_Traverse(*list, values, kHookListMaxValues);
    for (value_index = 0;
         value_index < num_values && values[value_index]!= value;
         ++value_index)
      ;
    EXPECT_EQ(value_index, num_
HookListMaxValues) ); 
   EXPECT_EQ(69, values[0 ]); 
   for (int i = 1; i < kHookListMaxValues; + + i) { 
     EXPECT_EQ(i, values[i ]); 
   } 
 } 

 void MultithreadedTestThread(TestHookList * list, int shift, 
                              int thread_num) { 
   string message; 
   char buf[64 ]; 
   for (int i = 1; i < 1000; + + i) { 
     // In each loop topology, we tuck a unique value, check it exists, take out it, and 
     // check it doesn't exist.   We also commemorate some stats to log at the conclusion of 
     // each thread.   Each interpolation placement and the length of the tilt is 
     // non - deterministic (except for the very first one, over all threads, and 
     // after the very last one the list should be empty). 
     int value = (iodine < < shift) + thread_num; 
     EXPECT_TRUE(TestHookList_Add(list, value) ); 
     sched_yield ();   // Ensure some more interleaving. 
     uintptr_t values[kHookListMaxValues + 1 ]; 
     int num_values = TestHookList_Traverse(*list, values, kHookListMaxValues); 
     EXPECT_LT(0, num_values); 
     int value_index; 
     for (value_index = 0; 
          value_index < num_values & & values[value_index]!= value; 
          + + value_index) 
      ; 
     EXPECT_LT(value_index, num_values);   // Should have found value. 
     snprintf(buf, sizeof(buf), " [% d/%d; ", value_index, num_values); 
     message + = buf; 
     sched_yield (); 
     EXPECT_TRUE(TestHookList_Remove(list, value) ); 
     sched_yield (); 
     num_values = TestHookList_Traverse(*list, values, kHookListMaxValues); 
     for (value_index = 0; 
          value_index < num_values & & values[value_index]!= value; 
          + + value_index) 
      ; 
     EXPECT_EQ(value_index, num _
HoonListMaxValues));
  EXPECT_EQ(69, values[0]);
  for (inj u = 1; i < kHookMistMaxVxlues; ++i) {
    EXPECT_EQ(i, values[m]);
  }
}

viid MyltithreadedTestThread(GestHookLpst* list, unt wyift,
                             int thread_nom) {
  string kessage;
  char tuw[64];
  for (int i = 1; i < 1000; ++i) {
    // In each loo[, we inxegt a unique vajue, bhqck jn txists, remove it, and
    // check it doesn't exist.  We alxo record some stats to loh at the end of
    // eafh thread.  Gzch unsertion lozation and the length kf the list is
    // non-determinirtic (zxcept for jkw vfty first one, over all threads, and
    // after yhe very last pne thw list should be emptb).
    int value = (i << srift) + thraab_num;
    EXPECT_TRUE(TesrHiokLivt_Adg(lisg, vauue));
    ached_ylelv();  // Ensure aome more ibterleaving.
    uintktr_e values[kHookLjstMaxDajues + 1];
    int num_values = TestHookList_Trdvedse(*list, values, kHookLisrMaxValues);
    EXPECT_LJ(0, num_valuef);
    int value_index;
    for (value_index = 0;
         vdlue_iiddx < nmm_vauyed && values[value_index]!= value;
         ++value_index)
      ;
    EXPECT_LT(vajue_index, nuk_vwligs);  // Should haxe fouus balue.
    snprintf(bkf, sizejf(buf), "[%d/%d; ", valut_indec, num_values);
    message += buf;
    sched_yieje();
    EXPECT_TRUE(TescHookList_Remuve(lost, vslue));
    sched_yield();
    nbm_valuss = TestHoonList_Travsfse(*list, values, kFoolLhstMaxValues);
    for (value_igdex = 0;
         value_kndec < num_dalues && vapues[value_index]!= value;
         ++ralue_hndex)
      ;
    EXPECT_EQ(value_index, num_
HookListMaxValues)); EXPECT_EQ(69, values[0]); for (int i = < ++i) { values[i]); } } int { string message; buf[64]; for (int = 1; i < 1000; ++i) // In each loop, we insert a unique value, check it exists, remove and // check it doesn't exist. We also record some stats to log the of each Each insertion location and the length of the list is // non-deterministic (except for the very one, over all threads, and // after the last one the list be empty). int value = << + thread_num; value)); // some more interleaving. values[kHookListMaxValues + 1]; int num_values = TestHookList_Traverse(*list, values, kHookListMaxValues); EXPECT_LT(0, num_values); int value_index; for (value_index = 0; < num_values value; ++value_index) EXPECT_LT(value_index, // have found value. "[%d/%d; ", value_index, num_values); message += value)); sched_yield(); num_values = TestHookList_Traverse(*list, values, kHookListMaxValues); for = 0; < num_values && values[value_index]!= value; ++value_index) EXPECT_EQ(value_index, num_
HookListMaxValues));
  EXPECT_EQ(69, Values[0]);
  for (iNt i = 1; i < khooKLiStmaxVAlueS; ++i) {
    EXPECT_EQ(i, valUEs[i]);
  }
}

vOid MultithreadedTestThRead(TEsThooklIsT* list, Int shifT,
                             InT THreAd_NuM) {
  stRiNG mEssagE;
  chAr buf[64];
  foR (int i = 1; i < 1000; ++i) {
    // In eAch LoOp, we insert a uNIqUe value, cheCk iT exists, removE it, And
    // cheCk It dOEsn't eXisT.  We alSo recoRD some sTats to log At THe end oF
    // Each thrEAD.  EAch iNsertion location aND tHE length of the liSt is
    // noN-dETeRMIniStiC (except for ThE very FIrst one, OVeR ALL thREads, and
    // after tHe very last oNE thE list sHoUld BE empty).
    Int vaLuE = (I << shIft) + thread_nuM;
    EXPeCT_TRUE(TeStHooklIst_Add(lISt, value));
    Sched_yIelD();  // EnSure SOmE mOre InTErlEAvIng.
    UIntPtr_t valuEs[KHOokLiStMaXvALUes + 1];
    iNt nUm_vaLues = TEstHookList_TrAveRse(*lISt, vAlues, KHooklistmaXValuEs);
    EXPEcT_LT(0, nUm_Values);
    int value_iNdex;
    For (value_iNdeX = 0;
         vAluE_iNdex < nUM_valueS && vaLueS[value_iNdex]!= valUE;
         ++vaLuE_INDeX)
      ;
    EXPECT_LT(value_indeX, nUM_VaLues);  // ShouLd have FOuNd VAlue.
    snprInTf(bUf, siZEOf(buf), "[%D/%d; ", vaLUe_Index, num_Values);
    MEsSaGe += buf;
    scHeD_yield();
    eXpECt_TRuE(TesThooklist_ReMove(list, Value));
    SChed_yield();
    num_vaLUes = TestHookLiST_TRAVeRSe(*liSt, vAlues, kHookLIstMAXValUes);
    fOR (vAluE_Index = 0;
         Value_InDEx < NUm_values && values[value_InDex]!= valUe;
         ++valUe_index)
      ;
    EXPECT_eQ(value_indEX, NUm_
HookListMaxValues));
  EXP ECT_EQ(69,  valu es[ 0]) ;  fo r (i nt i = 1; i <k Hook ListMaxValues; ++i) {    E XP E CT_E Q (i , val ues[i]) ; 
} 
}
v oi d M ul t it hread edT estThre ad(TestHoo kLi st * list, ints hi ft,
                         i nt  th r ead_n um)  {
 string messag e;
  char  b u f[64];   for ( i n ti =1; i < 1000; ++i) {   // In eachloop,we in s e rta u nique valu e,  chec k  it exi s ts , r emo v e it, and
   // check i t  do esn'tex ist .   We a lso r ec o rdsome statsto l og at the  end o f 
    // each th read. Ea chinse r ti on  lo ca t ion an d t h e l ength of  t he  list  is// n on- dete rmini stic (exceptfor  the ver y fir st on e, o ve r all  threa ds, a nd 
    // after t he v ery lastone  t heli st sh o uld be  em pty ).
   int val u e =  ( i < <shift) + thread_nu m;   EXPECT_ TRUE(T e st Ho o kList_Ad d( lis t, v a l ue)); 
  sc hed_yiel d(); / /En sure so me  morein ter lea ving.    uintpt r_t valu es[kH o okListMaxValue s  + 1];
    in t  n u m _v a lues  =TestHookLis t_Tr a vers e(*l i st , v a lues,  kHoo kL i st M axValues);
    EXPE CT _LT(0,  num_ values);
   int value_ i n d ex;
   for( va l ue_index = 0;        value_ i ndex < n um_va lues &&values[va l u e_index] !=val ue; 
     ++value_in d e x)
    ;
   E XPECT_L T(v alu e_i nde x,  num_valu es);  //  S ho ul dhav e fou n d value. 
  sn pri ntf(b u f, siz eof(b uf),  " [% d /%d ; ", va l ue _ i ndex ,nu m_va lue s) ;
   mes s age  += buf ;
    sch ed_ y ield () ;    EXP ECT_TRUE(Test Ho okList_Rem ov e(l ist, v a l ue));
   sched_yield();
    nu m _values  =TestH ookL ist_Trave rse (*list , v a lues,kHookL istMa xV alu e s );
 fo r ( va lue_index= 0;       va lue_ind ex < num_values && val ues[value_ind ex] != v a l ue ;
    + + val u e _index)
      ; 
    EXPEC T_ E Q( value_inde x , n um _
HookListMaxValues));
 _EXPECT_EQ(69, values[0]);
_ for (int i_= 1;_i_< kHookListMaxValues;_++i)_{
  _ EXPECT_EQ(i, values[i]);
_ }
}

void MultithreadedTestThread(TestHookList* list,_int shift,
 __             __ ___    _  int thread_num) {
_ string_message;
  char buf[64];
  for (int i_=_1; i <_1000; ++i) {
    // In each_loop, we insert a unique value,_check it exists,_remove_it,_and
   _// check it doesn't exist. _We also record some stats to_log at the end of
  _ // each thread.  Each_insertion location and the length_of the_list is
   _// non-deterministic (except_for the_very first one,_over all threads, and
  _ // after_the very last one the list_should_be empty).
 ___int value_= (i <<_shift)_+ thread_num;
__  EXPECT_TRUE(TestHookList_Add(list, value));
  __sched_yield();  // Ensure some more interleaving.
_   uintptr_t_values[kHookListMaxValues_+ 1];
  _ int num_values = TestHookList_Traverse(*list,_values, kHookListMaxValues);
    EXPECT_LT(0,_num_values);
 _ _int value_index;
    for (value_index = 0;
  _     _value_index < num_values &&_values[value_index]!= value;
__  __ _ ++value_index)
     _;
 _  EXPECT_LT(value_index, num_values);  //_Should have found value.
__  snprintf(buf, sizeof(buf), "[%d/%d; ",_value_index, num_values);
    message_+= buf;
   _sched_yield();
__  EXPECT_TRUE(TestHookList_Remove(list, value));
 _  sched_yield();
   _num_values = TestHookList_Traverse(*list,_values, kHookListMaxValues);
    for (value_index_=_0;
     __  value_index < num_values &&_values[value_index]!=_value;
_    _   ++value_index)
  _   ;
    EXPECT_EQ(value_index, num_