ReactOS 0.4.15-dev-7924-g5949c20
mutex.c File Reference
#include <windows.h>
#include <string.h>
#include <stdio.h>
Include dependency graph for mutex.c:

Go to the source code of this file.

Functions

void dprintf (char *fmt,...)
 
DWORD WINAPI thread1 (LPVOID crap)
 
DWORD WINAPI thread2 (LPVOID crap)
 
int main (int argc, char *argv[])
 

Variables

HANDLE OutputHandle
 
HANDLE InputHandle
 
HANDLE hThread [2]
 
DWORD dwCounter = 0
 
HANDLE hMutex
 

Function Documentation

◆ dprintf()

void dprintf ( char fmt,
  ... 
)

Definition at line 14 of file mutex.c.

15{
17 char buffer[255];
18
22 va_end(args);
23}
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
#define NULL
Definition: types.h:112
BOOL WINAPI DECLSPEC_HOTPATCH WriteConsoleA(IN HANDLE hConsoleOutput, IN CONST VOID *lpBuffer, IN DWORD nNumberOfCharsToWrite, OUT LPDWORD lpNumberOfCharsWritten, LPVOID lpReserved)
Definition: readwrite.c:1468
GLuint buffer
Definition: glext.h:5915
int __cdecl vsprintf(char *_Dest, const char *_Format, va_list _Args)
Definition: sprintf.c:733
HANDLE OutputHandle
Definition: mutex.c:6
#define args
Definition: format.c:66
Definition: match.c:390
Definition: dsound.c:943

◆ main()

int main ( int argc  ,
char argv[] 
)

Definition at line 88 of file mutex.c.

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}
HANDLE WINAPI GetStdHandle(IN DWORD nStdHandle)
Definition: console.c:203
BOOL WINAPI AllocConsole(VOID)
Definition: console.c:74
#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
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
#define INFINITE
Definition: serial.h:102
unsigned long DWORD
Definition: ntddk_ex.h:95
HANDLE InputHandle
Definition: mutex.c:7
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
#define L(x)
Definition: ntvdm.h:50
#define dprintf
Definition: regdump.c:33
DWORD WINAPI WaitForMultipleObjects(IN DWORD nCount, IN CONST HANDLE *lpHandles, IN BOOL bWaitAll, IN DWORD dwMilliseconds)
Definition: synch.c:151
HANDLE WINAPI DECLSPEC_HOTPATCH CreateMutexW(IN LPSECURITY_ATTRIBUTES lpMutexAttributes OPTIONAL, IN BOOL bInitialOwner, IN LPCWSTR lpName OPTIONAL)
Definition: synch.c:576
#define STD_OUTPUT_HANDLE
Definition: winbase.h:268
#define STD_INPUT_HANDLE
Definition: winbase.h:267
DWORD WINAPI GetLastError(void)
Definition: except.c:1042

◆ thread1()

DWORD WINAPI thread1 ( LPVOID  crap)

Definition at line 26 of file mutex.c.

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}
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
DWORD dwCounter
Definition: mutex.c:10
DWORD WINAPI WaitForSingleObject(IN HANDLE hHandle, IN DWORD dwMilliseconds)
Definition: synch.c:82
BOOL WINAPI DECLSPEC_HOTPATCH ReleaseMutex(IN HANDLE hMutex)
Definition: synch.c:618
#define WAIT_ABANDONED_0
Definition: winbase.h:407
#define WAIT_FAILED
Definition: winbase.h:413

Referenced by main().

◆ thread2()

DWORD WINAPI thread2 ( LPVOID  crap)

Definition at line 57 of file mutex.c.

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}

Referenced by main().

Variable Documentation

◆ dwCounter

DWORD dwCounter = 0

Definition at line 10 of file mutex.c.

Referenced by GetTextSid(), GetTextualSid(), thread1(), and thread2().

◆ hMutex

◆ hThread

HANDLE hThread[2]

Definition at line 9 of file mutex.c.

Referenced by main().

◆ InputHandle

HANDLE InputHandle

Definition at line 7 of file mutex.c.

Referenced by main().

◆ OutputHandle

HANDLE OutputHandle

Definition at line 6 of file mutex.c.

Referenced by dprintf(), and main().