Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // task 1.cpp: определяет точку входа для консольного приложения.
- //
- #include "stdafx.h"
- #include <iostream>
- #include <Windows.h>
- using namespace std;
- const int N=15;
- double Array[N];
- HANDLE hEvent;
- DWORD WINAPI exchange(LPVOID param)
- {
- double fict;
- WaitForSingleObject(hEvent,INFINITE);
- for (int i=1;i<N;i++)
- {
- if (Array[i-1]>Array[i])
- {
- fict=Array[i];
- Array[i]=Array[i-1];
- Array[i-1]=fict;
- }
- if (i==(N/2))
- {
- SetEvent(hEvent);
- }
- }
- return 0;
- }
- int _tmain(int argc, _TCHAR* argv[])
- {
- int i;
- HANDLE hThread[N-1];
- DWORD dwThreadID[N-1];
- cout<<"It was:"<<endl;
- for (i=0;i<N;i++)
- {
- Array[i]=rand()%1000;
- cout<<Array[i]<<" ";
- }
- cout<<endl;
- hEvent=CreateEvent(NULL,TRUE,TRUE,NULL);
- for (i=0;i<N-1;i++)
- {
- hThread[i]=CreateThread(NULL,0,exchange,NULL,0,&dwThreadID[i]);
- }
- WaitForMultipleObjects(N-1,hThread,true,INFINITE);
- cout<<"Now it is:"<<endl;
- for (i=0;i<N;i++)
- {
- cout<<Array[i]<<" ";
- }
- cout<<endl;
- system("pause");
- return 0;
- }
Add Comment
Please, Sign In to add comment