1// Licensed to the .NET Foundation under one or more agreements.
2// The .NET Foundation licenses this file to you under the MIT license.
3// See the LICENSE file in the project root for more information.
4
5/*============================================================
6**
7** Source: test.c
8**
9** Purpose: InterlockedIncrement() function
10**
11**
12**=========================================================*/
13
14/* This test is FINISHED. Note: The biggest feature of this function is that
15 it locks the value before it increments it -- in order to make it so only
16 one thread can access it. But, I really don't have a great test to make
17 sure it's thread safe. Any ideas? Nothing I've tried has worked.
18*/
19
20
21#include <palsuite.h>
22
23int __cdecl main(int argc, char *argv[])
24{
25
26 int TheValue = 0;
27 int TheReturn;
28
29 /*
30 * Initialize the PAL and return FAILURE if this fails
31 */
32
33 if(0 != (PAL_Initialize(argc, argv)))
34 {
35 return FAIL;
36 }
37
38 InterlockedIncrement(&TheValue);
39 TheReturn = InterlockedIncrement(&TheValue);
40
41 /* Incremented twice, it should be 2 now */
42 if(TheValue != 2)
43 {
44 Fail("ERROR: The value was incremented twice and shoud now be 2, "
45 "but it is really %d",TheValue);
46 }
47
48 /* Check to make sure it returns itself */
49 if(TheReturn != TheValue)
50 {
51 Fail("ERROR: The function should return the new value, which shoud "
52 "have been %d, but it returned %d.",TheValue,TheReturn);
53 }
54
55 PAL_Terminate();
56 return PASS;
57}
58
59
60
61
62
63