ReactOS 0.4.15-dev-5666-gc548b97
mutex.c
Go to the documentation of this file.
1#include <windows.h>
2#include <string.h>
3#include <stdio.h>
4
5
8
12
13
14void dprintf(char* fmt, ...)
15{
17 char buffer[255];
18
22 va_end(args);
23}
24
25
27{
28 DWORD dwError = 0;
29 DWORD i;
30
31 dprintf("Thread 1 running!\n");
32
33 for (i = 0; i < 10; i++)
34 {
36 if (dwError == WAIT_FAILED)
37 {
38 dprintf("Thread2: WaitForSingleObject failed!\n");
39 return 1;
40 }
41 else if (dwError == WAIT_ABANDONED_0)
42 {
43 dprintf("Thread2: WaitForSingleObject returned WAIT_ABANDONED_0\n");
44 }
45
46 dprintf("Thread1: dwCounter : %lu -->", dwCounter);
47 dwCounter++;
48 dprintf(" %lu\n", dwCounter);
50 }
51
52 dprintf("Thread 1 done!\n");
53
54 return 1;
55}
56
58{
59 DWORD dwError = 0;
60 DWORD i;
61 dprintf("Thread 2 running!\n");
62
63 for (i = 0; i < 10; i++)
64 {
66 if (dwError == WAIT_FAILED)
67 {
68 dprintf("Thread2: WaitForSingleObject failed!\n");
69 return 1;
70 }
71 else if (dwError == WAIT_ABANDONED_0)
72 {
73 dprintf("Thread2: WaitForSingleObject returned WAIT_ABANDONED_0\n");
74 }
75
76 dprintf("Thread2: dwCounter : %lu -->", dwCounter);
77 dwCounter++;
78 dprintf(" %lu\n", dwCounter);
80 }
81
82 dprintf("Thread 2 done!\n");
83
84 return 1;
85}
86
87
88int main(int argc, char* argv[])
89{
90 DWORD dwError;
91 DWORD id1,id2;
92
96
97 dprintf("Calling CreateMutex()\n");
98 hMutex = CreateMutexW(NULL, FALSE, L"TestMutex");
100 {
101 dprintf("CreateMutex() failed! Error: %lu\n", GetLastError());
102 return 0;
103 }
104 dprintf("CreateMutex() succeeded!\n");
105
106 hThread[0] = CreateThread(0, 0, thread1, 0, 0, &id1);
107 hThread[1] = CreateThread(0, 0, thread2, 0, 0, &id2);
108
109 dprintf("Calling WaitForMultipleObject()\n");
111 dprintf("WaitForMultipleObject() Error: %lu\n", dwError);
112
115
117
118 dprintf("Main thread done!\n");
119
120 return 0;
121}
static int argc
Definition: ServiceArgs.c:12
ACPI_SIZE strlen(const char *String)
Definition: utclib.c:269
char * va_list
Definition: acmsvcex.h:78
#define va_end(ap)
Definition: acmsvcex.h:90
#define va_start(ap, A)
Definition: acmsvcex.h:91
HANDLE WINAPI GetStdHandle(IN DWORD nStdHandle)
Definition: console.c:203
BOOL WINAPI AllocConsole(VOID)
Definition: console.c:74
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
#define CloseHandle
Definition: compat.h:739
#define INVALID_HANDLE_VALUE
Definition: compat.h:731
BOOL WINAPI DECLSPEC_HOTPATCH WriteConsoleA(IN HANDLE hConsoleOutput, IN CONST VOID *lpBuffer, IN DWORD nNumberOfCharsToWrite, OUT LPDWORD lpNumberOfCharsWritten, LPVOID lpReserved)
Definition: readwrite.c:1468
HANDLE WINAPI DECLSPEC_HOTPATCH CreateThread(IN LPSECURITY_ATTRIBUTES lpThreadAttributes, IN DWORD dwStackSize, IN LPTHREAD_START_ROUTINE lpStartAddress, IN LPVOID lpParameter, IN DWORD dwCreationFlags, OUT LPDWORD lpThreadId)
Definition: thread.c:137
int main()
Definition: test.c:6
#define INFINITE
Definition: serial.h:102
unsigned long DWORD
Definition: ntddk_ex.h:95
GLuint buffer
Definition: glext.h:5915
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
int __cdecl vsprintf(char *_Dest, const char *_Format, va_list _Args)
Definition: sprintf.c:733
HANDLE InputHandle
Definition: mutex.c:7
DWORD dwCounter
Definition: mutex.c:10
HANDLE hThread[2]
Definition: mutex.c:9
HANDLE hMutex
Definition: mutex.c:11
DWORD WINAPI thread1(LPVOID crap)
Definition: mutex.c:26
DWORD WINAPI thread2(LPVOID crap)
Definition: mutex.c:57
HANDLE OutputHandle
Definition: mutex.c:6
#define argv
Definition: mplay32.c:18
#define L(x)
Definition: ntvdm.h:50
#define dprintf
Definition: regdump.c:33
#define args
Definition: format.c:66
Definition: match.c:390
Definition: dsound.c:943
DWORD WINAPI WaitForMultipleObjects(IN DWORD nCount, IN CONST HANDLE *lpHandles, IN BOOL bWaitAll, IN DWORD dwMilliseconds)
Definition: synch.c:151
DWORD WINAPI WaitForSingleObject(IN HANDLE hHandle, IN DWORD dwMilliseconds)
Definition: synch.c:82
HANDLE WINAPI DECLSPEC_HOTPATCH CreateMutexW(IN LPSECURITY_ATTRIBUTES lpMutexAttributes OPTIONAL, IN BOOL bInitialOwner, IN LPCWSTR lpName OPTIONAL)
Definition: synch.c:576
BOOL WINAPI DECLSPEC_HOTPATCH ReleaseMutex(IN HANDLE hMutex)
Definition: synch.c:618
#define STD_OUTPUT_HANDLE
Definition: winbase.h:268
#define STD_INPUT_HANDLE
Definition: winbase.h:267
DWORD WINAPI GetLastError(void)
Definition: except.c:1040
#define WAIT_ABANDONED_0
Definition: winbase.h:407
#define WAIT_FAILED
Definition: winbase.h:413
#define WINAPI
Definition: msvc.h:6