⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 subject_67092.htm

📁 vc
💻 HTM
📖 第 1 页 / 共 4 页
字号:
<p>
序号:67092 发表者:badboy 发表日期:2003-12-29 12:32:45
<br>主题:函数里的形参里有“, ...”你见过吗?
<br>内容:下面有个程序的源代码,其中有个函数void AddStr (LPCTSTR szFmt, ...) ,您<BR><BR>见过这种形式的参数定义吗? 后面那三个点想干什么?在下面的代码中还真有那<BR><BR>么多调用这个函数AddStr()时,还真要这么用,源代码的作者想干什么?AddStr<BR><BR>(__TEXT(&#34;%04lu: Leaving checkout counter.&#34;),nShopperNum);<BR>AddStr(__TEXT(&#34;%04lu: Checking out (%lu).&#34;),nShopperNum, nDuration); <BR><BR>&nbsp;&nbsp;&nbsp;&nbsp;<BR><BR><BR><BR><BR>/***********************************************************<BR>Module name: SprMrkt.C<BR>Notices: Copyright (c) 1995-1997 Jeffrey Richter<BR>***********************************************************/<BR><BR><BR>#include &#34;..\CmnHdr.H&#34;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;/* See Appendix C. */<BR>#include &lt;windows.h&gt;<BR>#include &lt;windowsx.h&gt;<BR>#include &lt;tchar.h&gt;<BR>#include &lt;stdio.h&gt;<BR>#include &lt;stdlib.h&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;// For random number stuff<BR>#include &lt;string.h&gt;<BR>#include &lt;stdarg.h&gt;<BR>#include &lt;process.h&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // For _beginthreadex<BR>#include &#34;Resource.H&#34;<BR><BR><BR>///////////////////////////////////////////////////////////<BR><BR><BR>// This is the correction to a bug in windowsx.h:<BR>#undef FORWARD_WM_HSCROLL<BR>#define FORWARD_WM_HSCROLL(hwnd, hwndCtl, code, pos, fn) \<BR>&nbsp;&nbsp;&nbsp;&nbsp;(void)(fn)((hwnd), WM_HSCROLL, \<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; MAKEWPARAM((UINT)(code),(UINT)(pos)), \<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; (LPARAM)(UINT)(hwndCtl))<BR><BR><BR>///////////////////////////////////////////////////////////<BR><BR><BR>// Forward references to the supermarket<BR>// and shopper thread functions.<BR>DWORD WINAPI ThreadSuperMarket (LPVOID lpvParam);<BR>DWORD WINAPI ThreadShopper (LPVOID lpvParam);<BR><BR><BR>//////////////////////////////////////////////////////////////<BR><BR><BR>// Global variables<BR>HWND g_hwndLB = NULL;&nbsp;&nbsp; // List box for shopper events<BR><BR>// User-settable simulation parameters.<BR>int g_nMaxOccupancy;<BR>int g_nTimeOpen;<BR>int g_nCheckoutCounters;<BR>int g_nMaxDelayBetweenShopperCreation;<BR>int g_nMaxWaitToGetInMarket;<BR>int g_nMaxTimeShopping;<BR>int g_nMaxWaitForDeliCntr;<BR>int g_nMaxTimeSpentAtDeli;<BR>int g_nMaxTimeAtCheckout;<BR><BR>// Synchronization objects used to control the simulation<BR>HANDLE g_hSemEntrance;<BR>HANDLE g_hMtxDeliCntr;<BR>HANDLE g_hSemCheckout;<BR><BR><BR>//////////////////////////////////////////////////////////////<BR><BR><BR>// This function constructs a string using the format string<BR>// passed and the variable number of arguments and adds the<BR>// string to the shopper events list box identified by the<BR>// global g_hwndLB variable.<BR>void AddStr (LPCTSTR szFmt, ...) <BR>{<BR>&nbsp;&nbsp; TCHAR szBuf[150];<BR>&nbsp;&nbsp; int nIndex;<BR>&nbsp;&nbsp; va_list va_params;<BR><BR>&nbsp;&nbsp; // Make va_params point to the first argument after szFmt.<BR>&nbsp;&nbsp; va_start(va_params, szFmt);<BR><BR>&nbsp;&nbsp; // Build the string to be displayed.<BR>&nbsp;&nbsp; _vstprintf(szBuf, szFmt, va_params);<BR>&nbsp;&nbsp; do {<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;// Add the string to the end of the list box.<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;nIndex = ListBox_AddString(g_hwndLB, szBuf);<BR><BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;// If the list box is full, delete the first item in it.<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if (nIndex == LB_ERR)<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ListBox_DeleteString(g_hwndLB, 0);<BR><BR>&nbsp;&nbsp; } while (nIndex == LB_ERR);<BR><BR>&nbsp;&nbsp; // Select the newly added item.<BR>&nbsp;&nbsp; ListBox_SetCurSel(g_hwndLB, nIndex);<BR><BR>&nbsp;&nbsp; // Indicate that we are done referencing<BR>&nbsp;&nbsp; // the variable arguments.<BR>&nbsp;&nbsp; va_end(va_params);<BR>}<BR><BR><BR>//////////////////////////////////////////////////////////////<BR><BR><BR>// This function returns a random number<BR>// between 0 and nMaxValue, inclusive.<BR>int Random (int nMaxValue) {<BR>&nbsp;&nbsp; return(rand() / (RAND_MAX / (nMaxValue + 1)));<BR>}<BR><BR><BR>//////////////////////////////////////////////////////////////<BR><BR><BR>BOOL Dlg_OnInitDialog (HWND hwnd, HWND hwndFocus,<BR>&nbsp;&nbsp; LPARAM lParam) {<BR><BR>&nbsp;&nbsp; HWND hwndSB;<BR><BR>&nbsp;&nbsp; // Associate an icon with the dialog box.<BR>&nbsp;&nbsp; chSETDLGICONS(hwnd, IDI_SPRMRKT, IDI_SPRMRKT);<BR><BR>&nbsp;&nbsp; // Save the window handle to the shopper events list box<BR>&nbsp;&nbsp; // in a global variable so that the AddStr function has<BR>&nbsp;&nbsp; // access to it.<BR>&nbsp;&nbsp; g_hwndLB = GetDlgItem(hwnd, IDC_SHOPPEREVENTS);<BR><BR>&nbsp;&nbsp; // Set the scroll bar range and default positions for all of<BR>&nbsp;&nbsp; // the simulation parameters.<BR>&nbsp;&nbsp; hwndSB = GetDlgItem(hwnd, IDC_MAXOCCUPANCY);<BR>&nbsp;&nbsp; ScrollBar_SetRange(hwndSB, 0, 500, TRUE);<BR><BR>&nbsp;&nbsp; // Set the initial value of the scroll bar.<BR>&nbsp;&nbsp; FORWARD_WM_HSCROLL(hwnd, hwndSB, SB_THUMBTRACK,<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;30, SendMessage);<BR><BR><BR>&nbsp;&nbsp; hwndSB = GetDlgItem(hwnd, IDC_TIMEOPEN);<BR>&nbsp;&nbsp; ScrollBar_SetRange(hwndSB, 0, 5000, TRUE);<BR>&nbsp;&nbsp; FORWARD_WM_HSCROLL(hwnd, hwndSB, SB_THUMBTRACK,<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;5000, SendMessage);<BR><BR>&nbsp;&nbsp; hwndSB = GetDlgItem(hwnd, IDC_NUMCOUNTERS);<BR>&nbsp;&nbsp; ScrollBar_SetRange(hwndSB, 0, 30, TRUE);<BR>&nbsp;&nbsp; FORWARD_WM_HSCROLL(hwnd, hwndSB, SB_THUMBTRACK,<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;5, SendMessage);<BR><BR>&nbsp;&nbsp; hwndSB = GetDlgItem(hwnd, IDC_SHOPPERCREATIONDELAY);<BR>&nbsp;&nbsp; ScrollBar_SetRange(hwndSB, 0, 1000, TRUE);<BR>&nbsp;&nbsp; FORWARD_WM_HSCROLL(hwnd, hwndSB, SB_THUMBTRACK,<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;300, SendMessage);<BR><BR>&nbsp;&nbsp; hwndSB = GetDlgItem(hwnd, IDC_DELAYTOGETIN);<BR>&nbsp;&nbsp; ScrollBar_SetRange(hwndSB, 0, 100, TRUE);<BR>&nbsp;&nbsp; FORWARD_WM_HSCROLL(hwnd, hwndSB, SB_THUMBTRACK,<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;20, SendMessage);<BR><BR>&nbsp;&nbsp; hwndSB = GetDlgItem(hwnd, IDC_TIMETOSHOP);<BR>&nbsp;&nbsp; ScrollBar_SetRange(hwndSB, 0, 100, TRUE);<BR>&nbsp;&nbsp; FORWARD_WM_HSCROLL(hwnd, hwndSB, SB_THUMBTRACK,<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;80, SendMessage);<BR><BR>&nbsp;&nbsp; hwndSB = GetDlgItem(hwnd, IDC_WAITDELICNTR);<BR>&nbsp;&nbsp; ScrollBar_SetRange(hwndSB, 0, 100, TRUE);<BR>&nbsp;&nbsp; FORWARD_WM_HSCROLL(hwnd, hwndSB, SB_THUMBTRACK,<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;20, SendMessage);<BR><BR>&nbsp;&nbsp; hwndSB = GetDlgItem(hwnd, IDC_TIMEATDELICNTR);<BR>&nbsp;&nbsp; ScrollBar_SetRange(hwndSB, 0, 100, TRUE);<BR>&nbsp;&nbsp; FORWARD_WM_HSCROLL(hwnd, hwndSB, SB_THUMBTRACK,<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;70, SendMessage);<BR><BR>&nbsp;&nbsp; hwndSB = GetDlgItem(hwnd, IDC_TIMEATCHECKOUT);<BR>&nbsp;&nbsp; ScrollBar_SetRange(hwndSB, 0, 100, TRUE);<BR>&nbsp;&nbsp; FORWARD_WM_HSCROLL(hwnd, hwndSB, SB_THUMBTRACK,<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;60, SendMessage);<BR><BR>&nbsp;&nbsp; return(TRUE);<BR>}<BR><BR><BR>//////////////////////////////////////////////////////////////<BR><BR><BR>void Dlg_OnHScroll(HWND hwnd, HWND hwndCtl,<BR>&nbsp;&nbsp; UINT code, int pos) {<BR><BR>&nbsp;&nbsp; TCHAR szBuf[10];<BR>&nbsp;&nbsp; int nPosCrnt, nPosMin, nPosMax;<BR><BR>&nbsp;&nbsp; // Get the current position and the legal range for the<BR>&nbsp;&nbsp; // scroll bar that the user is changing.<BR>&nbsp;&nbsp; nPosCrnt = ScrollBar_GetPos(hwndCtl);<BR>&nbsp;&nbsp; ScrollBar_GetRange(hwndCtl, &amp;nPosMin, &amp;nPosMax);<BR><BR>&nbsp;&nbsp; switch (code) {<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;case SB_LINELEFT:<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; nPosCrnt--;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; break;<BR><BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;case SB_LINERIGHT:<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; nPosCrnt++;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; break;<BR><BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;case SB_PAGELEFT:<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; nPosCrnt -= (nPosMax - nPosMin + 1) / 10;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; break;<BR><BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;case SB_PAGERIGHT:<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; nPosCrnt += (nPosMax - nPosMin + 1) / 10;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; break;<BR><BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;case SB_THUMBTRACK:<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; nPosCrnt = pos;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; break;<BR><BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;case SB_LEFT:<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; nPosCrnt = nPosMin;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; break;<BR><BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;case SB_RIGHT:<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; nPosCrnt = nPosMax;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; break;<BR>&nbsp;&nbsp; }<BR><BR>&nbsp;&nbsp; // Make sure that the new scroll bar position<BR>&nbsp;&nbsp; // is within the legal range.<BR>&nbsp;&nbsp; if (nPosCrnt &lt; nPosMin)<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;nPosCrnt = nPosMin;<BR><BR>&nbsp;&nbsp; if (nPosCrnt &gt; nPosMax)<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;nPosCrnt = nPosMax;<BR><BR>&nbsp;&nbsp; // Set the new scroll bar position.<BR>&nbsp;&nbsp; ScrollBar_SetPos(hwndCtl, nPosCrnt, TRUE);<BR><BR>&nbsp;&nbsp; // Change the value displayed in the text box to<BR>&nbsp;&nbsp; // reflect the value in the scroll bar.<BR>&nbsp;&nbsp; _stprintf(szBuf, __TEXT(&#34;%d&#34;), nPosCrnt);<BR>&nbsp;&nbsp; SetWindowText(GetPrevSibling(hwndCtl), szBuf);<BR>}<BR><BR><BR>//////////////////////////////////////////////////////////////<BR><BR><BR>void Dlg_OnCommand (HWND hwnd, int id, HWND hwndCtl,<BR>&nbsp;&nbsp; UINT codeNotify) {<BR><BR>&nbsp;&nbsp; DWORD dwThreadId;<BR>&nbsp;&nbsp; HANDLE hThread;<BR><BR>&nbsp;&nbsp; switch (id) {<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;case IDOK:<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // Load the scroll bar settings into the global<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // variables so that they can be used<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // by the simulation.<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; g_nMaxOccupancy = ScrollBar_GetPos(<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;GetDlgItem(hwnd, IDC_MAXOCCUPANCY));<BR><BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; g_nTimeOpen = ScrollBar_GetPos(<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;GetDlgItem(hwnd, IDC_TIMEOPEN));<BR><BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; g_nCheckoutCounters = ScrollBar_GetPos(<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;GetDlgItem(hwnd, IDC_NUMCOUNTERS));<BR><BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; g_nMaxDelayBetweenShopperCreation = ScrollBar_GetPos(<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;GetDlgItem(hwnd, IDC_SHOPPERCREATIONDELAY));<BR><BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; g_nMaxWaitToGetInMarket = ScrollBar_GetPos(<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;GetDlgItem(hwnd, IDC_DELAYTOGETIN));<BR><BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; g_nMaxTimeShopping = ScrollBar_GetPos(<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;GetDlgItem(hwnd, IDC_TIMETOSHOP));<BR><BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; g_nMaxWaitForDeliCntr = ScrollBar_GetPos(<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;GetDlgItem(hwnd, IDC_WAITDELICNTR));<BR><BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; g_nMaxTimeSpentAtDeli = ScrollBar_GetPos(<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;GetDlgItem(hwnd, IDC_TIMEATDELICNTR));<BR><BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; g_nMaxTimeAtCheckout = ScrollBar_GetPos(<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;GetDlgItem(hwnd, IDC_TIMEATCHECKOUT));<BR><BR><BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // Clear out everything in the list box.<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ListBox_ResetContent(GetDlgItem(hwnd, IDC_SHOPPEREVENTS));<BR><BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // Disable the Open For Business button<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // while simulation is in progress.<BR><BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; EnableWindow(hwndCtl, FALSE);<BR><BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if (NULL == GetFocus()) {<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;SetFocus(GetDlgItem(hwnd, IDC_MAXOCCUPANCY));<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<BR><BR><BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // The system overhead will cause the results<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // of the simulation to be skewed. To help<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // minimize this effect, we boost the priority class<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // of this process.<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; SetPriorityClass(GetCurrentProcess(),<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;HIGH_PRIORITY_CLASS);<BR><BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // Create the thread representing the supermarket.<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; hThread = chBEGINTHREADEX(<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;NULL,&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;// Security attributes<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;0,&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // Stack<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ThreadSuperMarket, // Thread function<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;(LPVOID) hwnd,&nbsp;&nbsp;&nbsp;&nbsp; // Thread function parameter<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;0,&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // Flags<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&amp;dwThreadId);&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;// Thread ID&nbsp;&nbsp;&nbsp;&nbsp;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // Since we are not interested in manipulating the<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // thread object from this function, we can close<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // our handle to it.<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; CloseHandle(hThread);<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; break;<BR><BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;case IDCANCEL:<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; EndDialog(hwnd, id);<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; break;<BR>&nbsp;&nbsp; }<BR>}<BR><BR><BR>//////////////////////////////////////////////////////////////<BR><BR><BR>BOOL CALLBACK Dlg_Proc (HWND hwnd, UINT uMsg,<BR>&nbsp;&nbsp; WPARAM wParam, LPARAM lParam) {<BR><BR>&nbsp;&nbsp; switch (uMsg) {<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; chHANDLE_DLGMSG(hwnd, WM_INITDIALOG,&nbsp;&nbsp;Dlg_OnInitDialog);<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;chHANDLE_DLGMSG(hwnd, WM_COMMAND,&nbsp;&nbsp;Dlg_OnCommand);<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;chHANDLE_DLGMSG(hwnd, WM_HSCROLL,&nbsp;&nbsp;Dlg_OnHScroll);<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<BR><BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;case WM_USER:<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // This message is sent by the SuperMarketThread <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // function to notify us that the simulation <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // has completed.<BR><BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // Return the priority class of the simulation<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // back to normal.<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; SetPriorityClass(GetCurrentProcess(),<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;NORMAL_PRIORITY_CLASS);<BR><BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // Enable the Open For Business button so that<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // the user can run the simulation again with<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // new parameters.<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; EnableWindow(GetDlgItem(hwnd, IDOK), TRUE);<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; break;<BR>&nbsp;&nbsp; }<BR>&nbsp;&nbsp; return(FALSE);<BR>}<BR><BR><BR>//////////////////////////////////////////////////////////////<BR><BR><BR>int WINAPI _tWinMain (HINSTANCE hinstExe,<BR>&nbsp;&nbsp; HINSTANCE hinstPrev, LPTSTR pszCmdLine, int nCmdShow) {<BR><BR>&nbsp;&nbsp; chWARNIFUNICODEUNDERWIN95();<BR>&nbsp;&nbsp; DialogBox(hinstExe, MAKEINTRESOURCE(IDD_SPRMRKT),<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;NULL, Dlg_Proc);<BR><BR>&nbsp;&nbsp; return(0);<BR>}<BR><BR><BR>//////////////////////////////////////////////////////////////<BR><BR><BR>DWORD WINAPI ThreadSuperMarket (LPVOID lpvParam) {<BR>&nbsp;&nbsp; DWORD dwCloseTime;<BR>&nbsp;&nbsp; HANDLE hThread;<BR>&nbsp;&nbsp; DWORD dwThreadId;<BR>&nbsp;&nbsp; int nShopperNum = 0, nMaxOccupancy;<BR><BR>&nbsp;&nbsp; g_hSemEntrance = CreateSemaphore(<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;NULL,&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;// Security attributes<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;0,&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // Initial lock count<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;g_nMaxOccupancy,&nbsp;&nbsp;&nbsp;&nbsp; // Maximum people allowed in store<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;NULL);&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // Do not name the semaphore.<BR><BR>&nbsp;&nbsp; g_hMtxDeliCntr = CreateMutex(<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;NULL,&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;// Security attributes<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;FALSE,&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // Initially no one is at the deli.<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;NULL);&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // Do not name the mutex.<BR><BR>&nbsp;&nbsp; g_hSemCheckout = CreateSemaphore(<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;NULL,&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;// Security attributes<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;g_nCheckoutCounters, // All counters are free.<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;g_nCheckoutCounters, // The number of counters at the store<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;NULL);&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // No name for the semaphore<BR><BR><BR>&nbsp;&nbsp; // Open the store to the shoppers.<BR>&nbsp;&nbsp; AddStr(__TEXT(&#34;---&gt; Opening the supermarket to shoppers.&#34;));<BR>&nbsp;&nbsp; ReleaseSemaphore(g_hSemEntrance, g_nMaxOccupancy, NULL);<BR><BR>&nbsp;&nbsp; // Get the time at which the store should<BR>&nbsp;&nbsp; // stop creating shoppers.<BR>&nbsp;&nbsp; dwCloseTime = GetTickCount() + g_nTimeOpen;<BR><BR>&nbsp;&nbsp; // Continue loop until the store closes.<BR>&nbsp;&nbsp; while (GetTickCount() &lt; dwCloseTime) {<BR><BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;// Create the thread representing a shopper.<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;hThread = chBEGINTHREADEX(<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; NULL,&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // Security attributes<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 0,&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;// Stack<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ThreadShopper,&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;// Thread function<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; (LPVOID) ++nShopperNum, // Shopper number as lpvParam<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 0,&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;// Flags<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &amp;dwThreadId);&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // Thread ID<BR><BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;// Since we are not interested in manipulating the<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;// thread object from this function, we can close<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;// our handle to it.<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;CloseHandle(hThread);<BR><BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;// Wait until another shopper comes to the supermarket.<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Sleep(Random(g_nMaxDelayBetweenShopperCreation));<BR>&nbsp;&nbsp; }<BR><BR>&nbsp;&nbsp; // The supermarket wants to close;<BR>&nbsp;&nbsp; // wait for all of the shoppers to leave.<BR>&nbsp;&nbsp; AddStr(__TEXT(&#34;---&gt; Waiting for shoppers to check out &#34;)<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;__TEXT(&#34;so store can close.&#34;));<BR><BR>&nbsp;&nbsp; nMaxOccupancy = 1;<BR>&nbsp;&nbsp; for (; nMaxOccupancy &lt;= g_nMaxOccupancy; nMaxOccupancy++) {<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;WaitForSingleObject(g_hSemEntrance, INFINITE);<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;AddStr(__TEXT(&#34;---&gt; %d shoppers NOT in store.&#34;),<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;nMaxOccupancy);<BR>&nbsp;&nbsp; }<BR><BR>&nbsp;&nbsp; AddStr(__TEXT(&#34;---&gt; Store closed--end of simulation.&#34;));<BR><BR>&nbsp;&nbsp; // Everybody has left the market--end of simulation.<BR>&nbsp;&nbsp; CloseHandle(g_hSemCheckout);<BR>&nbsp;&nbsp; CloseHandle(g_hMtxDeliCntr);<BR>&nbsp;&nbsp; CloseHandle(g_hSemEntrance);<BR><BR>&nbsp;&nbsp; // Notify the GUI thread that the simulation has completed.<BR>&nbsp;&nbsp; // The window handle of the GUI thread's dialog box was<BR>&nbsp;&nbsp; // passed in the lpvParam parameter to this thread when<BR>&nbsp;&nbsp; // it was created.<BR>&nbsp;&nbsp; SendMessage((HWND) lpvParam, WM_USER, 0, 0);<BR><BR>&nbsp;&nbsp; return(0);<BR>}<BR><BR><BR>//////////////////////////////////////////////////////////////<BR><BR><BR>DWORD WINAPI ThreadShopper (LPVOID lpvParam) {<BR>&nbsp;&nbsp; int nShopperNum = (int) lpvParam;<BR>&nbsp;&nbsp; DWORD dwResult;<BR>&nbsp;&nbsp; int nDuration;<BR><BR>&nbsp;&nbsp; // Seed the random number generator for this thread<BR>&nbsp;&nbsp; // or every shopper thread will use the same seed and<BR>&nbsp;&nbsp; // generate the same set of random numbers.<BR>&nbsp;&nbsp; srand(GetTickCount() * nShopperNum);<BR><BR>&nbsp;&nbsp; // Wait till the shopper can enter the supermarket.<BR>&nbsp;&nbsp; nDuration = Random(g_nMaxWaitToGetInMarket);<BR>&nbsp;&nbsp; AddStr(__TEXT(&#34;%04lu: Waiting to get in store (%lu).&#34;),<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;nShopperNum, nDuration);<BR><BR>&nbsp;&nbsp; dwResult = WaitForSingleObject(g_hSemEntrance, nDuration);<BR>&nbsp;&nbsp; if (dwResult == WAIT_TIMEOUT) {<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;// The shopper got tired of<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;// waiting to be let in and left.<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;AddStr(__TEXT(&#34;%04lu: Tired of waiting; went home.&#34;),<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;nShopperNum);<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return(0);<BR>&nbsp;&nbsp; }<BR><BR><BR>&nbsp;&nbsp; // Shopper entered the supermarket.&nbsp;&nbsp;Time to go shopping.<BR>&nbsp;&nbsp; nDuration = Random(g_nMaxTimeShopping);<BR>&nbsp;&nbsp; AddStr(__TEXT(&#34;%04lu: In supermarket, shopping for %lu.&#34;),<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;nShopperNum, nDuration);<BR>&nbsp;&nbsp; Sleep(nDuration);<BR><BR><BR>&nbsp;&nbsp; // Done with initial shopping. Shopper has a one-in-three<BR>&nbsp;&nbsp; // chance of going to the deli counter.<BR>&nbsp;&nbsp; if (Random(2) == 0) {<BR><BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;// Shopper going to deli counter.<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;nDuration = Random(g_nMaxWaitForDeliCntr);<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;AddStr(<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; __TEXT(&#34;%04lu: Waiting for service at &#34;)<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; __TEXT(&#34;Deli Counter (%lu).&#34;),<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; nShopperNum, nDuration);<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;dwResult =<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; WaitForSingleObject(g_hMtxDeliCntr, nDuration);<BR><BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if (dwResult == 0) {<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // Got attention at deli; order stuff.<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; nDuration = Random(g_nMaxTimeSpentAtDeli);<BR><BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; AddStr(__TEXT(&#34;%04lu: Being served at Deli (%lu).&#34;),<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;nShopperNum, nDuration);<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Sleep(nDuration);<BR><BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // Leave the deli counter.<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ReleaseMutex(g_hMtxDeliCntr);<BR><BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;} else {<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // Tired of waiting at deli counter,<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // leave and continue shopping.<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; AddStr(__TEXT(&#34;%04lu: Tired of waiting at Deli.&#34;),<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;nShopperNum);<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<BR><BR>&nbsp;&nbsp; } else {<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;AddStr(__TEXT(&#34;%04lu: Not going to the Deli counter.&#34;),<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; nShopperNum);<BR>&nbsp;&nbsp; }<BR><BR><BR>&nbsp;&nbsp; // Waiting for a checkout counter.<BR>&nbsp;&nbsp; AddStr(<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;__TEXT(&#34;%04lu: Waiting for an empty checkout counter.&#34;),<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;nShopperNum);<BR>&nbsp;&nbsp; WaitForSingleObject(g_hSemCheckout, INFINITE);<BR><BR>&nbsp;&nbsp; // Checking out.<BR>&nbsp;&nbsp; nDuration = Random(g_nMaxTimeAtCheckout);<BR>&nbsp;&nbsp; AddStr(__TEXT(&#34;%04lu: Checking out (%lu).&#34;),<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;nShopperNum, nDuration);<BR>&nbsp;&nbsp; Sleep(nDuration);<BR><BR>&nbsp;&nbsp; // Leaving the checkout counter.<BR>&nbsp;&nbsp; AddStr(__TEXT(&#34;%04lu: Leaving checkout counter.&#34;),<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;nShopperNum);<BR>&nbsp;&nbsp; ReleaseSemaphore(g_hSemCheckout, 1, NULL);<BR><BR>&nbsp;&nbsp; // Leaving the store.<BR>&nbsp;&nbsp; AddStr(__TEXT(&#34;%04lu: Left the supermarket.&#34;),<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;nShopperNum);<BR>&nbsp;&nbsp; ReleaseSemaphore(g_hSemEntrance, 1, NULL);<BR><BR>&nbsp;&nbsp; // Shopper shopped till he/she dropped.&nbsp;&nbsp;Shopper dead.<BR>&nbsp;&nbsp; return(0);<BR>}<BR><BR><BR>//////////////////////// End Of File /////////////////////////<BR>
<br><a href="javascript:history.go(-1)">返回上页</a><br><a href=http://www.copathway.com/cndevforum/>访问论坛</a></p>
<hr size=1>
<blockquote><p>
回复者:ljl 回复日期:2003-12-29 12:36:35
<br>内容:见过,就是表示后面的参数类型和个数不定
<br>
<a href="javascript:history.go(-1)">返回上页</a><br><a href=http://www.copathway.com/cndevforum/>访问论坛</a></p></blockquote>
<hr size=1>
<blockquote><p>
回复者:ljl 回复日期:2003-12-29 12:38:51
<br>内容:<BR>#include &lt;iostream&gt;<BR>#include &lt;string&gt;<BR><BR>using namespace std;<BR><BR>void fun(int i, ... )<BR>{<BR>&nbsp;&nbsp;&nbsp;&nbsp;cout &lt;&lt; &#34;Fun...&nbsp;&nbsp;... &#34; &lt;&lt; endl;<BR>}<BR><BR>void main()<BR>{<BR>&nbsp;&nbsp;&nbsp;&nbsp;fun(1);<BR>&nbsp;&nbsp;&nbsp;&nbsp;fun(1, &#34;abc&#34;);<BR>&nbsp;&nbsp;&nbsp;&nbsp;fun(1, 2);<BR>&nbsp;&nbsp;&nbsp;&nbsp;fun(1, 'a', 'b', 2, 2);<BR><BR>}<BR>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -