VirtualBox

source: vbox/trunk/src/VBox/Runtime/testcase/tstThread-1.cpp@ 18364

Last change on this file since 18364 was 11822, checked in by vboxsync, 16 years ago

IPRT: RTR3Init cleanup.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 3.7 KB
Line 
1/* $Id: tstThread-1.cpp 11822 2008-08-29 14:21:03Z vboxsync $ */
2/** @file
3 * IPRT Testcase - Thread Testcase no.1.
4 */
5
6/*
7 * Copyright (C) 2006-2007 Sun Microsystems, Inc.
8 *
9 * This file is part of VirtualBox Open Source Edition (OSE), as
10 * available from http://www.virtualbox.org. This file is free software;
11 * you can redistribute it and/or modify it under the terms of the GNU
12 * General Public License (GPL) as published by the Free Software
13 * Foundation, in version 2 as it comes in the "COPYING" file of the
14 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
15 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
16 *
17 * The contents of this file may alternatively be used under the terms
18 * of the Common Development and Distribution License Version 1.0
19 * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
20 * VirtualBox OSE distribution, in which case the provisions of the
21 * CDDL are applicable instead of those of the GPL.
22 *
23 * You may elect to license modified versions of this file under the
24 * terms and conditions of either the GPL or the CDDL or both.
25 *
26 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
27 * Clara, CA 95054 USA or visit http://www.sun.com if you need
28 * additional information or have any questions.
29 */
30
31/*******************************************************************************
32* Header Files *
33*******************************************************************************/
34#include <iprt/thread.h>
35#include <iprt/stream.h>
36#include <iprt/initterm.h>
37#include <iprt/err.h>
38
39
40/*******************************************************************************
41* Global Variables *
42*******************************************************************************/
43static unsigned volatile g_cErrors = 0;
44
45
46static DECLCALLBACK(int) tstThread1ReturnImmediately(RTTHREAD Thread, void *pvUser)
47{
48 NOREF(pvUser);
49 return VINF_SUCCESS;
50}
51
52
53
54int main(int argc, const char * const *argv)
55{
56 RTR3Init();
57
58 /*
59 * A simple testcase for the termination race we used to have.
60 */
61 RTTHREAD ahThreads[128];
62 RTPrintf("tstThread-1: TESTING - %u waitable immediate return threads\n", RT_ELEMENTS(ahThreads));
63 for (unsigned j = 0; j < 10; j++)
64 {
65 RTPrintf("tstThread-1: Iteration %u...\n", j);
66 for (unsigned i = 0; i < RT_ELEMENTS(ahThreads); i++)
67 {
68 int rc = RTThreadCreate(&ahThreads[i], tstThread1ReturnImmediately, &ahThreads[i], 0, RTTHREADTYPE_DEFAULT, RTTHREADFLAGS_WAITABLE, "TEST1");
69 if (RT_FAILURE(rc))
70 {
71 RTPrintf("tstThread-1: FAILURE(%d) - %d/%d RTThreadCreate failed, rc=%Rrc\n", __LINE__, i, j, rc);
72 g_cErrors++;
73 ahThreads[i] = NIL_RTTHREAD;
74 }
75 }
76
77 /*
78 * Wait for the threads to complete.
79 */
80 for (unsigned i = 0; i < RT_ELEMENTS(ahThreads); i++)
81 if (ahThreads[i] != NIL_RTTHREAD)
82 {
83 int rc2;
84 int rc = RTThreadWait(ahThreads[i], RT_INDEFINITE_WAIT, &rc2);
85 if (RT_FAILURE(rc))
86 {
87 RTPrintf("tstThread-1: FAILURE(%d) - %d/%d RTThreadWait failed, rc=%Rrc\n", __LINE__, j, i, rc);
88 g_cErrors++;
89 }
90 else if (RT_FAILURE(rc2))
91 {
92 RTPrintf("tstThread-1: FAILURE(%d) - %d/%d Thread failed, rc2=%Rrc\n", __LINE__, j, i, rc2);
93 g_cErrors++;
94 }
95 }
96 }
97
98 /*
99 * Summary.
100 */
101 if (!g_cErrors)
102 RTPrintf("tstThread-1: SUCCESS\n");
103 else
104 RTPrintf("tstThread-1: FAILURE - %d errors\n", g_cErrors);
105
106 return !!g_cErrors;
107}
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette