InsertRecs.cpp
上传用户:romrleung
上传日期:2022-05-23
资源大小:18897k
文件大小:21k
源码类别:

MySQL数据库

开发平台:

Visual C++

  1. /* Copyright (C) 2003 MySQL AB
  2.    This program is free software; you can redistribute it and/or modify
  3.    it under the terms of the GNU General Public License as published by
  4.    the Free Software Foundation; either version 2 of the License, or
  5.    (at your option) any later version.
  6.    This program is distributed in the hope that it will be useful,
  7.    but WITHOUT ANY WARRANTY; without even the implied warranty of
  8.    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  9.    GNU General Public License for more details.
  10.    You should have received a copy of the GNU General Public License
  11.    along with this program; if not, write to the Free Software
  12.    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */
  13. // InsertRecs.cpp : Defines the entry point for the console application.
  14. //
  15. #include <NdbApi.hpp>
  16. #include <windows.h>
  17. #include <tchar.h>
  18. // data for CALL_CONTEXT and GROUP_RESOURCE
  19. static TCHAR STATUS_DATA[]=_T("000102030405060708090A0B0C0D0E0F000102030405060708090A0B0C0D0E0F")
  20.    _T("101112131415161718191A1B1C1D1E1F000102030405060708090A0B0C0D0E0F")
  21.    _T("202122232425262728292A2B2C2D2E2F000102030405060708090A0B0C0D0E0F")
  22.    _T("303132333435363738393A3B3C3D3E3F000102030405060708090A0B0C0D0E0F")
  23.    _T("404142434445464748494A4B4C4D4E4F000102030405060708090A0B0C0D0E0F")
  24.    _T("505152535455565758595A5B5C5D5E5F000102030405060708090A0B0C0D0E0F")
  25.    _T("606162636465666768696A6B6C6D6E6F000102030405060708090A0B0C0D0E0F")
  26.    _T("707172737475767778797A7B7C7D7E7F000102030405060708090A0B0C0D0E0F")
  27.    _T("808182838485868788898A8B8C8D8E8F000102030405060708090A0B0C0D0E0F")
  28.    _T("909192939495969798999A9B9C9D9E9F000102030405060708090A0B0C0D0E0F")
  29.    _T("10010110210310410510610710810910A000102030405060708090A0B0C0D0EF")
  30.    _T("10B10C10D10E10F110111112113114115000102030405060708090A0B0C0D0EF")
  31.    _T("11611711811911A11B11C11D11E11F120000102030405060708090A0B0C0D0EF")
  32.    _T("12112212312412512612712812912A12B000102030405060708090A0B0C0D0EF")
  33.    _T("12C12D12E12F130131132134135136137000102030405060708090A0B0C0D0EF")
  34.    _T("13813913A13B13C13D13E13F140141142000102030405060708090A0B0C0D0EF")
  35.    _T("14314414514614714814914A14B14C14D000102030405060708090A0B0C0D0EF")
  36.    _T("14E14F150151152153154155156157158000102030405060708090A0B0C0D0EF")
  37.    _T("15915A15B15C15D15E15F160161162163000102030405060708090A0B0C0D0EF")
  38.    _T("16416516616716816916A16B16C16D16E000102030405060708090A0B0C0D0EF")
  39.    _T("16F170171172173174175176177178179000102030405060708090A0B0C0D0EF")
  40.    _T("17A17B17C17D17E17F180181182183184000102030405060708090A0B0C0D0EF")
  41.    _T("18518618718818918A18B18C18D18E18F000102030405060708090A0B0C0D0EF")
  42.    _T("19019119219319419519619719819919A000102030405060708090A0B0C0D0EF")
  43.    _T("19B19C19D19E19F200201202203204205000102030405060708090A0B0C0D0EF")
  44.    _T("20620720820920A20B20C20D20F210211000102030405060708090A0B0C0D0EF")
  45.    _T("21221321421521621721821921A21B21C000102030405060708090A0B0C0D0EF")
  46.    _T("21D21E21F220221222223224225226227000102030405060708090A0B0C0D0EF")
  47.    _T("22822922A22B22C22D22E22F230231232000102030405060708090A0B0C0D0EF")
  48.    _T("23323423523623723823923A23B23C23D000102030405060708090A0B0C0D0EF")
  49.    _T("23E23F240241242243244245246247248000102030405060708090A0B0C0D0EF")
  50.    _T("24924A24B24C24D24E24F250251252253000102030405060708090A0B0C0D0EF")
  51.    _T("101112131415161718191A1B1C1D1E1F000102030405060708090A0B0C0D0E0F")
  52.    _T("202122232425262728292A2B2C2D2E2F000102030405060708090A0B0C0D0E0F")
  53.    _T("303132333435363738393A3B3C3D3E3F000102030405060708090A0B0C0D0E0F")
  54.    _T("404142434445464748494A4B4C4D4E4F000102030405060708090A0B0C0D0E0F")
  55.    _T("505152535455565758595A5B5C5D5E5F000102030405060708090A0B0C0D0E0F")
  56.    _T("606162636465666768696A6B6C6D6E6F000102030405060708090A0B0C0D0E0F")
  57.    _T("707172737475767778797A7B7C7D7E7F000102030405060708090A0B0C0D0E0F")
  58.    _T("808182838485868788898A8B8C8D8E8F000102030405060708090A0B0C0D0E0F")
  59.    _T("909192939495969798999A9B9C9D9E9F000102030405060708090A0B0C0D0E0F")
  60.    _T("10010110210310410510610710810910A000102030405060708090A0B0C0D0EF")
  61.    _T("10B10C10D10E10F110111112113114115000102030405060708090A0B0C0D0EF")
  62.    _T("11611711811911A11B11C11D11E11F120000102030405060708090A0B0C0D0EF")
  63.    _T("12112212312412512612712812912A12B000102030405060708090A0B0C0D0EF")
  64.    _T("12C12D12E12F130131132134135136137000102030405060708090A0B0C0D0EF")
  65.    _T("13813913A13B13C13D13E13F140141142000102030405060708090A0B0C0D0EF")
  66.    _T("14314414514614714814914A14B14C14D000102030405060708090A0B0C0D0EF")
  67.    _T("14E14F150151152153154155156157158000102030405060708090A0B0C0D0EF")
  68.    _T("15915A15B15C15D15E15F160161162163000102030405060708090A0B0C0D0EF")
  69.    _T("16416516616716816916A16B16C16D16E000102030405060708090A0B0C0D0EF")
  70.    _T("16F170171172173174175176177178179000102030405060708090A0B0C0D0EF")
  71.    _T("17A17B17C17D17E17F180181182183184000102030405060708090A0B0C0D0EF")
  72.    _T("18518618718818918A18B18C18D18E18F000102030405060708090A0B0C0D0EF")
  73.    _T("19019119219319419519619719819919A000102030405060708090A0B0C0D0EF")
  74.    _T("19B19C19D19E19F200201202203204205000102030405060708090A0B0C0D0EF")
  75.    _T("20620720820920A20B20C20D20F210211000102030405060708090A0B0C0D0EF")
  76.    _T("21221321421521621721821921A21B21C000102030405060708090A0B0C0D0EF")
  77.    _T("21D21E21F220221222223224225226227000102030405060708090A0B0C0D0EF")
  78.    _T("22822922A22B22C22D22E22F230231232000102030405060708090A0B0C0D0EF")
  79.    _T("23323423523623723823923A23B23C23D000102030405060708090A0B0C0D0EF")
  80.    _T("2366890FE1438751097E7F6325DC0E6326F")
  81.    _T("25425525625725825925A25B25C25D25E25F000102030405060708090A0B0C0F");
  82. // Thread function for Call Context Inserts
  83. struct _ParamStruct
  84. {
  85. HANDLE hShutdownEvent;
  86. int nStartingRecordNum;
  87. long* pnNumCallsProcessed;
  88. };
  89. HANDLE hShutdownEvent = 0;
  90. BOOL WINAPI ConsoleCtrlHandler(DWORD dwCtrlType)
  91. {
  92. if(CTRL_C_EVENT == dwCtrlType)
  93. {
  94. SetEvent(hShutdownEvent);
  95. return TRUE;
  96. }
  97. return FALSE;
  98. }
  99. DWORD WINAPI RuntimeCallContext(LPVOID lpParam)
  100. {
  101.     long nNumCallsProcessed = 0;
  102. struct _ParamStruct* pData = (struct _ParamStruct*)lpParam;
  103.     int nStartingRecordID = pData->nStartingRecordNum;
  104.     Ndb* pNdb;
  105.     NdbConnection* pNdbConnection;
  106.     NdbOperation* pNdbOperation;
  107.     NdbRecAttr* pNdbRecAttrContextData;
  108.     char pchContextData[4008];
  109. LARGE_INTEGER freq;
  110. LARGE_INTEGER liStartTime, liEndTime;
  111.     pNdb = new Ndb("TEST_DB");
  112.     if(!pNdb)
  113.     {
  114.         printf("new Ndb failedn");
  115.         return 0;
  116.     }
  117.     try
  118.     {
  119.         if(pNdb->init(1)
  120.             || pNdb->waitUntilReady())
  121.         {
  122.             throw pNdb;
  123.         }
  124.         while(WaitForSingleObject(pData->hShutdownEvent,0) != WAIT_OBJECT_0)
  125.         {
  126.             nStartingRecordID++;
  127. bool bTimeLatency = (nStartingRecordID == 100) ? TRUE : FALSE;
  128. if (bTimeLatency)
  129. {
  130. BOOL bSuccess = QueryPerformanceFrequency(&freq);
  131. if (!bSuccess)
  132. printf("Error retrieving frequency: %dn", GetLastError());
  133. }
  134.             for (int i=0; i < 20; i++)
  135.             {
  136.                 switch(i)
  137.                 {
  138.                     case 3:
  139.                     case 6:
  140.                     case 9: 
  141.                     case 11: 
  142.                     case 12: 
  143.                     case 15: 
  144.                     case 18:   // Query Record
  145. if (bTimeLatency)
  146.    QueryPerformanceCounter(&liStartTime);
  147.                         pNdbConnection = pNdb->startTransaction((Uint32)0, (const char*)&nStartingRecordID, (Uint32)4);
  148.                         if(!pNdbConnection)
  149.                         {
  150.                             throw pNdb;
  151.                         }
  152.                         pNdbOperation = pNdbConnection->getNdbOperation(_T("CallContext"));
  153.                         if(!pNdbOperation)
  154.                         {
  155.                             throw pNdbConnection;
  156.                         }
  157.                         if(pNdbOperation->readTuple()
  158.                             || pNdbOperation->equal(_T("ContextId"), nStartingRecordID))
  159.                         {
  160.                             throw pNdbOperation;
  161.                         }
  162.                         pNdbRecAttrContextData = pNdbOperation->getValue(_T("ContextData"), pchContextData);
  163.                         if(!pNdbRecAttrContextData)
  164.                         {
  165.                             throw pNdbOperation;
  166.                         }
  167.                         if(pNdbConnection->execute(Commit))
  168.                         {
  169.                             throw pNdbConnection;
  170.                         }
  171.                         pNdb->closeTransaction(pNdbConnection);
  172. if (bTimeLatency)
  173. {
  174. QueryPerformanceCounter(&liEndTime);
  175. printf("Read = %d msec.n", (liEndTime.QuadPart - liStartTime.QuadPart) / (freq.QuadPart/1000));
  176. }
  177.                         break;
  178.                     case 19:    // Delete Record
  179.                         if (bTimeLatency)
  180.                             QueryPerformanceCounter(&liStartTime);
  181.                         
  182.                         pNdbConnection = pNdb->startTransaction((Uint32)0, (const char*)&nStartingRecordID, (Uint32)4);
  183.                         if(!pNdbConnection)
  184.                         {
  185.                             throw pNdb;
  186.                         }
  187.                         pNdbOperation = pNdbConnection->getNdbOperation(_T("CallContext"));
  188.                         if(!pNdbOperation)
  189.                         {
  190.                             throw pNdbConnection;
  191.                         }
  192.                         if(pNdbOperation->deleteTuple()
  193.                             || pNdbOperation->equal(_T("ContextId"), nStartingRecordID))
  194.                         {
  195.                             throw pNdbOperation;
  196.                         }
  197.                         if(pNdbConnection->execute(Commit))
  198.                         {
  199.                             throw pNdbConnection;
  200.                         }
  201.                         pNdb->closeTransaction(pNdbConnection);
  202.                         
  203. if (bTimeLatency)
  204. {
  205. QueryPerformanceCounter(&liEndTime);
  206. printf("Delete = %d msec.n", (liEndTime.QuadPart - liStartTime.QuadPart) / (freq.QuadPart/1000));
  207. }
  208.                         break;
  209.                     case 0: // Insert Record
  210. if (bTimeLatency)
  211.    QueryPerformanceCounter(&liStartTime);
  212.                         pNdbConnection = pNdb->startTransaction((Uint32)0, (const char*)&nStartingRecordID, (Uint32)4);
  213.                         if(!pNdbConnection)
  214.                         {
  215.                             throw pNdb;
  216.                         }
  217.                         pNdbOperation = pNdbConnection->getNdbOperation(_T("CallContext"));
  218.                         if(!pNdbOperation)
  219.                         {
  220.                             throw pNdbConnection;
  221.                         }
  222.                         if(pNdbOperation->insertTuple()
  223.                             || pNdbOperation->equal(_T("ContextId"), nStartingRecordID)
  224.                         || pNdbOperation->setValue(_T("Version"), Int32(1))
  225.                         || pNdbOperation->setValue(_T("LockFlag"), Int32(1))
  226.                         || pNdbOperation->setValue(_T("LockTime"), Int32(1))
  227.                         || pNdbOperation->setValue(_T("LockTimeUSec"), Int32(1))
  228.                         || pNdbOperation->setValue(_T("ContextData"), STATUS_DATA, sizeof(STATUS_DATA)))
  229.                         {
  230.                             throw pNdbOperation;
  231.                         }
  232.                         if(pNdbConnection->execute(Commit))
  233.                         {
  234.                             throw pNdbConnection;
  235.                         }
  236.                         pNdb->closeTransaction(pNdbConnection);
  237.                         
  238. if (bTimeLatency)
  239. {
  240. QueryPerformanceCounter(&liEndTime);
  241. printf("Insert = %d msec.n", (liEndTime.QuadPart - liStartTime.QuadPart) / (freq.QuadPart/1000));
  242. }
  243.                         break;
  244.                     default:    // Update Record
  245. if (bTimeLatency)
  246.    QueryPerformanceCounter(&liStartTime);
  247.                         pNdbConnection = pNdb->startTransaction((Uint32)0, (const char*)&nStartingRecordID, (Uint32)4);
  248.                         if(!pNdbConnection)
  249.                         {
  250.                             throw pNdb;
  251.                         }
  252.                         pNdbOperation = pNdbConnection->getNdbOperation(_T("CallContext"));
  253.                         if(!pNdbOperation)
  254.                         {
  255.                             throw pNdbConnection;
  256.                         }
  257.                         if(pNdbOperation->updateTuple())
  258.                         {
  259.                             throw pNdbOperation;
  260.                         }
  261.                         if(pNdbOperation->equal(_T("ContextId"), nStartingRecordID)
  262.                             || pNdbOperation->setValue(_T("ContextData"), STATUS_DATA, sizeof(STATUS_DATA)))
  263.                         {
  264.                             throw pNdbOperation;
  265.                         }
  266.                         if(pNdbConnection->execute(Commit))
  267.                         {
  268.                             throw pNdbConnection;
  269.                         }
  270.                         pNdb->closeTransaction(pNdbConnection);
  271. if (bTimeLatency)
  272. {
  273. QueryPerformanceCounter(&liEndTime);
  274. printf("Update = %d msec.n", (liEndTime.QuadPart - liStartTime.QuadPart) / (freq.QuadPart/1000));
  275. }
  276.                         
  277. break;
  278.                 }
  279.             }
  280. nNumCallsProcessed++;
  281.             InterlockedIncrement(pData->pnNumCallsProcessed);
  282.         }
  283.         delete pNdb;
  284.     }
  285.     catch(Ndb* pNdb)
  286.     {
  287.         printf("%d: nt%snt%sn",
  288.             pNdb->getNdbError(), 
  289.             pNdb->getNdbErrorString(), 
  290.             "Ndb");
  291.         delete pNdb;
  292.     }
  293.     catch(NdbConnection* pNdbConnection)
  294.     {
  295.         printf("%d: nt%snt%sn",
  296.             pNdbConnection->getNdbError(), 
  297.             pNdbConnection->getNdbErrorString(), 
  298.             "NdbConnection");
  299.         pNdb->closeTransaction(pNdbConnection);
  300.         delete pNdb;
  301.     }
  302.     catch(NdbOperation* pNdbOperation)
  303.     {
  304.         printf("%d: nt%snt%sn",
  305.             pNdbOperation->getNdbError(), 
  306.             pNdbOperation->getNdbErrorString(), 
  307.             "NdbOperation");
  308.         pNdb->closeTransaction(pNdbConnection);
  309.         delete pNdb;
  310.     }
  311.     return 0;
  312. }
  313. void Initialize(Ndb* pNdb, long nInsert, bool bStoredTable)
  314. {
  315.     NdbSchemaCon* pNdbSchemaCon;
  316.     NdbSchemaOp* pNdbSchemaOp;
  317.     NdbConnection* pNdbConnection;
  318.     NdbOperation* pNdbOperation;
  319.     try
  320.     {
  321.         _tprintf(_T("Create CallContext tablen"));
  322.         pNdbSchemaCon = pNdb->startSchemaTransaction();
  323.         if(!pNdbSchemaCon)
  324.         {
  325.             throw pNdb;
  326.         }
  327.         pNdbSchemaOp = pNdbSchemaCon->getNdbSchemaOp();
  328.         if(!pNdbSchemaOp)
  329.         {
  330.             throw pNdbSchemaCon;
  331.         }
  332.         if(pNdbSchemaOp->createTable(_T("CallContext"), 8, TupleKey, 2, All, 6, 78, 80, 1, bStoredTable)
  333.             || pNdbSchemaOp->createAttribute(_T("ContextId"), TupleKey, 32, 1, Signed)
  334.             || pNdbSchemaOp->createAttribute(_T("Version"), NoKey, 32, 1, Signed)
  335.             || pNdbSchemaOp->createAttribute(_T("LockFlag"), NoKey, 32, 1, Signed)
  336.             || pNdbSchemaOp->createAttribute(_T("LockTime"), NoKey, 32, 1, Signed)
  337.             || pNdbSchemaOp->createAttribute(_T("LockTimeUSec"), NoKey, 32, 1, Signed)
  338.             || pNdbSchemaOp->createAttribute(_T("ContextData"), NoKey, 8, 4004, String))
  339.         {
  340.             throw pNdbSchemaOp;
  341.         }
  342.         if(pNdbSchemaCon->execute())
  343.         {
  344.             throw pNdbSchemaCon;
  345.         }
  346.         pNdb->closeSchemaTransaction(pNdbSchemaCon);
  347.         
  348.         _tprintf(_T("Insert %d tuples in the CallContext tablen"), nInsert);
  349.         for(long i=0; i<nInsert; ++i)
  350.         {
  351.             long iContextId = -i;
  352.             pNdbConnection = pNdb->startTransaction((Uint32)0, (const char*)&iContextId, (Uint32)4);
  353.             if(!pNdbConnection)
  354.             {
  355.                 throw pNdb;
  356.             }
  357.             pNdbOperation = pNdbConnection->getNdbOperation(_T("CallContext"));
  358.             if(!pNdbOperation)
  359.             {
  360.                 throw pNdbConnection;
  361.             }
  362.             if(pNdbOperation->insertTuple()
  363.                 || pNdbOperation->equal(_T("ContextId"), iContextId)
  364.                 || pNdbOperation->setValue(_T("Version"), Int32(1))
  365.                 || pNdbOperation->setValue(_T("LockFlag"), Int32(1))
  366.                 || pNdbOperation->setValue(_T("LockTime"), Int32(1))
  367.                 || pNdbOperation->setValue(_T("LockTimeUSec"), Int32(1))
  368.                 || pNdbOperation->setValue(_T("ContextData"), STATUS_DATA, sizeof(STATUS_DATA)))
  369.             {
  370.                 throw pNdbOperation;
  371.             }
  372.             if(pNdbConnection->execute(Commit))
  373.             {
  374.                 throw pNdbConnection;
  375.             }
  376.             pNdb->closeTransaction(pNdbConnection);
  377.         }
  378.         _tprintf(_T("initialisation donen"));
  379.     }
  380.     catch(Ndb* pNdb)
  381.     {
  382.         printf("%d: nt%snt%sn",
  383.             pNdb->getNdbError(), 
  384.             pNdb->getNdbErrorString(), 
  385.             "Ndb");
  386.         delete pNdb;
  387.     }
  388.     catch(NdbConnection* pNdbConnection)
  389.     {
  390.         printf("%d: nt%snt%sn",
  391.             pNdbConnection->getNdbError(), 
  392.             pNdbConnection->getNdbErrorString(), 
  393.             "NdbConnection");
  394.         pNdb->closeTransaction(pNdbConnection);
  395.         delete pNdb;
  396.     }
  397.     catch(NdbOperation* pNdbOperation)
  398.     {
  399.         printf("%d: nt%snt%sn",
  400.             pNdbOperation->getNdbError(), 
  401.             pNdbOperation->getNdbErrorString(), 
  402.             "NdbOperation");
  403.         pNdb->closeTransaction(pNdbConnection);
  404.         delete pNdb;
  405.     }
  406.     catch(NdbSchemaCon* pNdbSchemaCon)
  407.     {
  408.         printf("%d: nt%snt%sn",
  409.             pNdbSchemaCon->getNdbError(), 
  410.             pNdbSchemaCon->getNdbErrorString(), 
  411.             "pNdbSchemaCon");
  412.         pNdb->closeSchemaTransaction(pNdbSchemaCon);
  413.         delete pNdb;
  414.     }
  415.     catch(NdbSchemaOp* pNdbSchemaOp)
  416.     {
  417.         printf("%d: nt%snt%sn",
  418.             pNdbSchemaOp->getNdbError(), 
  419.             pNdbSchemaOp->getNdbErrorString(), 
  420.             "pNdbSchemaOp");
  421.         pNdb->closeTransaction(pNdbConnection);
  422.         delete pNdb;
  423.     }
  424. }
  425. int _tmain(int argc, _TCHAR* argv[])
  426. {
  427. long nNumThreads=4;
  428. long nSeed = 0;
  429.     long nInsert = 0;
  430.     bool bStoredTable = true;
  431. if(lstrcmp(argv[1],_T("/?")) == 0)
  432. {
  433. _tprintf(_T("InsertRecs [No.Of Threads] [Record Seed No.] [Init no. of rec.] [Stored?]n"));
  434. return 0;
  435. }
  436. if(argc > 1) 
  437.      nNumThreads = _ttol(argv[1]);
  438. else
  439. nNumThreads = 4;
  440. if (argc > 2)
  441. nSeed = _ttol(argv[2]);
  442. _tprintf(_T("Num of Threads = %d, Seed = %d"), nNumThreads, nSeed);
  443.     if(argc>3)
  444.         nInsert = _ttol(argv[3]);
  445.     if(argc>4)
  446.         bStoredTable = (_ttol(argv[4])!=0);
  447. long nNumCallsProcessed = 0;
  448.     SetConsoleCtrlHandler(ConsoleCtrlHandler,true); 
  449. hShutdownEvent = CreateEvent(NULL,TRUE,FALSE,NULL);
  450.    
  451.     // initiate windows sockets
  452.     WORD wVersionRequested;
  453.     WSADATA wsaData;
  454.     int err;
  455.     wVersionRequested = MAKEWORD( 2, 2 );
  456.     err = WSAStartup( wVersionRequested, &wsaData );
  457.     if ( err != 0 ) {
  458.         _tprintf(_T("could not find a usable WinSock DLLn"));
  459.         return 0;
  460.     }
  461.     if ( LOBYTE( wsaData.wVersion ) != 2 
  462.         || HIBYTE( wsaData.wVersion ) != 2 ) 
  463.     {
  464.         _tprintf(_T("could not find a usable WinSock DLLn"));
  465.         WSACleanup();
  466.         return 0;
  467.     }
  468.     Ndb* pNdb = new Ndb("TEST_DB");
  469.     if(!pNdb)
  470.     {
  471.         _tprintf(_T("could not construct ndbn"));
  472.         return 0;
  473.     }
  474.     if(pNdb->init(1)
  475.         || pNdb->waitUntilReady())
  476.     {
  477.         _tprintf(_T("could not initialize ndbn"));
  478.         return 0;
  479.     }
  480.     
  481.     if(nInsert>0)
  482.     {
  483.         Initialize(pNdb, nInsert, bStoredTable);
  484.     }
  485.     
  486.     if(nNumThreads>0)
  487.     {
  488.         _tprintf(_T("creating %d threadsn"), nNumThreads);
  489.         DWORD dwStartTime  = GetTickCount();
  490.         
  491.         DWORD dwThreadID = 0;
  492.         HANDLE hThreads[50];
  493.         
  494.         struct _ParamStruct params[50];
  495.         
  496.         for(int ij=0;ij<nNumThreads;ij++) {
  497.             params[ij].hShutdownEvent = hShutdownEvent;
  498.             params[ij].nStartingRecordNum = (ij*5000) + nSeed;
  499.             params[ij].pnNumCallsProcessed = &nNumCallsProcessed;
  500.         }
  501.         
  502.         for(ij=0;ij<nNumThreads;ij++) {
  503.             hThreads[ij] = CreateThread(NULL,NULL,RuntimeCallContext,&params[ij],0,&dwThreadID);
  504.         }
  505.         
  506.         //Wait for the threads to finish
  507.         WaitForMultipleObjects(nNumThreads,hThreads,TRUE,INFINITE);
  508.         DWORD dwEndTime  = GetTickCount();
  509.         
  510.         //Print time taken
  511.         _tprintf(_T("Time Taken for %d Calls is %ld msec (= %ld calls/secn"),
  512.             nNumCallsProcessed,dwEndTime-dwStartTime, (1000*nNumCallsProcessed/(dwEndTime-dwStartTime)));
  513.     }
  514.     delete pNdb;
  515.     WSACleanup();
  516. CloseHandle(hShutdownEvent);
  517.     return 0;
  518. }