ReactOS  0.4.14-dev-49-gfb4591c
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 {
16  va_list args;
17  char buffer[255];
18 
19  va_start(args,fmt);
22  va_end(args);
23 }
ACPI_SIZE strlen(const char *String)
Definition: utclib.c:269
GLuint buffer
Definition: glext.h:5915
Definition: match.c:390
HANDLE OutputHandle
Definition: mutex.c:6
#define va_end(ap)
Definition: acmsvcex.h:90
BOOL WINAPI DECLSPEC_HOTPATCH WriteConsoleA(IN HANDLE hConsoleOutput, IN CONST VOID *lpBuffer, IN DWORD nNumberOfCharsToWrite, OUT LPDWORD lpNumberOfCharsWritten, LPVOID lpReserved)
Definition: readwrite.c:1470
smooth NULL
Definition: ftsmooth.c:416
char * va_list
Definition: acmsvcex.h:78
int __cdecl vsprintf(char *_Dest, const char *_Format, va_list _Args)
Definition: sprintf.c:733
#define va_start(ap, A)
Definition: acmsvcex.h:91
#define args
Definition: format.c:66
Definition: dsound.c:943

Referenced by main(), thread1(), and thread2().

◆ main()

int main ( int argc  ,
char argv[] 
)

hosttype.c Copyright (C) 2002 by Brian Palmer brian.nosp@m.p@sg.nosp@m.inet..nosp@m.com

Definition at line 88 of file mutex.c.

89 {
90  DWORD dwError;
91  DWORD id1,id2;
92 
93  AllocConsole();
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 
113  CloseHandle(hThread[0]);
114  CloseHandle(hThread[1]);
115 
117 
118  dprintf("Main thread done!\n");
119 
120  return 0;
121 }
#define TRUE
Definition: types.h:120
BOOL WINAPI AllocConsole(VOID)
Definition: console.c:48
#define CloseHandle
Definition: compat.h:398
HANDLE InputHandle
Definition: mutex.c:7
#define INVALID_HANDLE_VALUE
Definition: compat.h:391
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1059
HANDLE WINAPI GetStdHandle(IN DWORD nStdHandle)
Definition: console.c:152
DWORD WINAPI WaitForMultipleObjects(IN DWORD nCount, IN CONST HANDLE *lpHandles, IN BOOL bWaitAll, IN DWORD dwMilliseconds)
Definition: synch.c:151
HANDLE OutputHandle
Definition: mutex.c:6
DWORD WINAPI thread2(LPVOID crap)
Definition: mutex.c:57
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:136
smooth NULL
Definition: ftsmooth.c:416
HANDLE hMutex
Definition: mutex.c:11
#define STD_INPUT_HANDLE
Definition: winbase.h:264
HANDLE hThread[2]
Definition: mutex.c:9
DWORD WINAPI thread1(LPVOID crap)
Definition: mutex.c:26
unsigned long DWORD
Definition: ntddk_ex.h:95
static const WCHAR L[]
Definition: oid.c:1250
#define STD_OUTPUT_HANDLE
Definition: winbase.h:265
void dprintf(char *fmt,...)
Definition: mutex.c:14
HANDLE WINAPI DECLSPEC_HOTPATCH CreateMutexW(IN LPSECURITY_ATTRIBUTES lpMutexAttributes OPTIONAL, IN BOOL bInitialOwner, IN LPCWSTR lpName OPTIONAL)
Definition: synch.c:576
#define INFINITE
Definition: serial.h:102

◆ 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 }
DWORD dwCounter
Definition: mutex.c:10
DWORD WINAPI WaitForSingleObject(IN HANDLE hHandle, IN DWORD dwMilliseconds)
Definition: synch.c:82
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
HANDLE hMutex
Definition: mutex.c:11
#define WAIT_ABANDONED_0
Definition: winbase.h:388
unsigned long DWORD
Definition: ntddk_ex.h:95
#define WAIT_FAILED
Definition: winbase.h:394
BOOL WINAPI DECLSPEC_HOTPATCH ReleaseMutex(IN HANDLE hMutex)
Definition: synch.c:618
void dprintf(char *fmt,...)
Definition: mutex.c:14
#define INFINITE
Definition: serial.h:102

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 }
DWORD dwCounter
Definition: mutex.c:10
DWORD WINAPI WaitForSingleObject(IN HANDLE hHandle, IN DWORD dwMilliseconds)
Definition: synch.c:82
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
HANDLE hMutex
Definition: mutex.c:11
#define WAIT_ABANDONED_0
Definition: winbase.h:388
unsigned long DWORD
Definition: ntddk_ex.h:95
#define WAIT_FAILED
Definition: winbase.h:394
BOOL WINAPI DECLSPEC_HOTPATCH ReleaseMutex(IN HANDLE hMutex)
Definition: synch.c:618
void dprintf(char *fmt,...)
Definition: mutex.c:14
#define INFINITE
Definition: serial.h:102

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().