VirtualBox

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

Last change on this file since 96407 was 96407, checked in by vboxsync, 2 years ago

scm copyright and license note update

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id Revision
File size: 4.2 KB
Line 
1/* $Id: tstThread-1.cpp 96407 2022-08-22 17:43:14Z vboxsync $ */
2/** @file
3 * IPRT Testcase - Thread Testcase no.1.
4 */
5
6/*
7 * Copyright (C) 2006-2022 Oracle and/or its affiliates.
8 *
9 * This file is part of VirtualBox base platform packages, as
10 * available from https://www.virtualbox.org.
11 *
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation, in version 3 of the
15 * License.
16 *
17 * This program is distributed in the hope that it will be useful, but
18 * WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 * General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, see <https://www.gnu.org/licenses>.
24 *
25 * The contents of this file may alternatively be used under the terms
26 * of the Common Development and Distribution License Version 1.0
27 * (CDDL), a copy of it is provided in the "COPYING.CDDL" file included
28 * in the VirtualBox distribution, in which case the provisions of the
29 * CDDL are applicable instead of those of the GPL.
30 *
31 * You may elect to license modified versions of this file under the
32 * terms and conditions of either the GPL or the CDDL or both.
33 *
34 * SPDX-License-Identifier: GPL-3.0-only OR CDDL-1.0
35 */
36
37
38/*********************************************************************************************************************************
39* Header Files *
40*********************************************************************************************************************************/
41#include <iprt/thread.h>
42#include <iprt/stream.h>
43#include <iprt/initterm.h>
44#include <iprt/errcore.h>
45
46
47/*********************************************************************************************************************************
48* Global Variables *
49*********************************************************************************************************************************/
50static unsigned volatile g_cErrors = 0;
51
52
53static DECLCALLBACK(int) tstThread1ReturnImmediately(RTTHREAD hSelf, void *pvUser)
54{
55 RT_NOREF_PV(hSelf); RT_NOREF_PV(pvUser);
56 return VINF_SUCCESS;
57}
58
59
60
61int main(int argc, char **argv)
62{
63 RTR3InitExe(argc, &argv, 0);
64
65 /*
66 * A simple testcase for the termination race we used to have.
67 */
68 RTTHREAD ahThreads[128];
69 RTPrintf("tstThread-1: TESTING - %u waitable immediate return threads\n", RT_ELEMENTS(ahThreads));
70 for (unsigned j = 0; j < 10; j++)
71 {
72 RTPrintf("tstThread-1: Iteration %u...\n", j);
73 for (unsigned i = 0; i < RT_ELEMENTS(ahThreads); i++)
74 {
75 int rc = RTThreadCreate(&ahThreads[i], tstThread1ReturnImmediately, &ahThreads[i], 0, RTTHREADTYPE_DEFAULT, RTTHREADFLAGS_WAITABLE, "TEST1");
76 if (RT_FAILURE(rc))
77 {
78 RTPrintf("tstThread-1: FAILURE(%d) - %d/%d RTThreadCreate failed, rc=%Rrc\n", __LINE__, i, j, rc);
79 g_cErrors++;
80 ahThreads[i] = NIL_RTTHREAD;
81 }
82 }
83
84 /*
85 * Wait for the threads to complete.
86 */
87 for (unsigned i = 0; i < RT_ELEMENTS(ahThreads); i++)
88 if (ahThreads[i] != NIL_RTTHREAD)
89 {
90 int rc2;
91 int rc = RTThreadWait(ahThreads[i], RT_INDEFINITE_WAIT, &rc2);
92 if (RT_FAILURE(rc))
93 {
94 RTPrintf("tstThread-1: FAILURE(%d) - %d/%d RTThreadWait failed, rc=%Rrc\n", __LINE__, j, i, rc);
95 g_cErrors++;
96 }
97 else if (RT_FAILURE(rc2))
98 {
99 RTPrintf("tstThread-1: FAILURE(%d) - %d/%d Thread failed, rc2=%Rrc\n", __LINE__, j, i, rc2);
100 g_cErrors++;
101 }
102 }
103 }
104
105 /*
106 * Summary.
107 */
108 if (!g_cErrors)
109 RTPrintf("tstThread-1: SUCCESS\n");
110 else
111 RTPrintf("tstThread-1: FAILURE - %d errors\n", g_cErrors);
112
113 return !!g_cErrors;
114}
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