Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //---------------------------------------------------------------------------
- #include <vcl.h>
- #pragma hdrstop
- #include <iostream.h>
- #include <conio.h>
- //---------------------------------------------------------------------------
- #pragma argsused
- HANDLE h1,h2;
- int globalCounter=0;
- VOID InitializeCriticalSection
- CRITICAL_SECTION sectiune_critica;
- DWORD WINAPI Increment_Contor1(){
- while(true){
- EnterCriticalSection(§iune_critica);
- for (int i=0; i<10; i++)
- {
- globalCounter++;
- printf("Thread1");
- printf("%d",i);
- printf("global");
- printf("%d", globalCounter);
- printf("\n");
- }
- LeaveCriticalSection(§iune_critica);
- }
- }
- DWORD WINAPI Increment_Contor2(){
- while(true){
- EnterCriticalSection(§iune_critica);
- for (int i=0; i<10; i++)
- {
- globalCounter++;
- printf("Thread2");
- printf("%d",i);
- printf("global");
- printf("%d", globalCounter);
- printf("\n");
- }
- LeaveCriticalSection(§iune_critica);
- }
- }
- int main(int argc, char* argv[])
- {
- h1=CreateThread(NULL,0,(PTHREAD_START_ROUTINE)Increment_Contor1,NULL,0,NULL);
- h2=CreateThread(NULL,0,(PTHREAD_START_ROUTINE)Increment_Contor2,NULL,0,NULL);
- getch();
- TerminateThread(h1,0);
- TerminateThread(h2,0);
- return 0;
- }
- //---------------------------------------------------------------------------
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement