[[semafor]]
 
#include "windows.h"
 
HANDLE s;
 
int f (void * p)
{
	int n = (int) p;
	while (true)
	{
	   WaitForSingleObject (s, INFINITE);
	   printf ("Kriticka sekce %d \n", n);
  	   ReleaseSemaphore (s, 1, NULL);
	}
}
 
int _tmain(int argc, _TCHAR* argv[])
{
	s = CreateSemaphore
	      (NULL, // security attr
	       1, // init
	       1, // max
               NULL // name
   	       );
 
	for (int i = 1; i <= 3; i++)
	   CreateThread (NULL, 0, 
	                 (LPTHREAD_START_ROUTINE)f, 
					 (void*)i, 
					 0, NULL);
 
	char c;
	scanf ("%c", &c);
	return 0;
}
 
semafor.txt · Last modified: 2013/04/09 11:10 by 147.32.8.115
 
Recent changes RSS feed Creative Commons License Donate Powered by PHP Valid XHTML 1.0 Valid CSS Driven by DokuWiki