006
26.01.2006, 09:13 Uhr
~NAHASA
Gast
|
ok ich glaub das war es ...... ich hab den Eventhandel einfach mal global gesetzt, da ich der 2 maligen Erzeugung nicht so ganz vertraut habe kann es sein das die WaitSingleObeject Event wieder zurücksetzt ?! Sieht jedenfalls ganz so aus hier noch mal der COde
Code: |
#include <cstdlib> #include <iostream> #include <windows.h> #include <process.h> #define N_EVENT1 "ne1" #define N_EVENT2 "ne2" #define repeat 100000 using namespace std;
void thread (PVOID pvoid); void thread2 (PVOID pvoid);
HANDLE hEvent1= CreateEvent(NULL,FALSE,FALSE,N_EVENT1); HANDLE hEvent2= CreateEvent(NULL,FALSE,FALSE,N_EVENT2); BOOL con1=TRUE; BOOL con2=TRUE; int main(int argc, char *argv[]) {
_beginthread(thread,0,NULL); _beginthread(thread2,0,NULL);
int i; while (true) { cin>>i; if (i==1) { con1=TRUE; SetEvent(hEvent1); } if (i==2) { con2=TRUE; SetEvent(hEvent2); } if (i==3) { con1=FALSE; ResetEvent(hEvent1); } if (i==4) { con2=FALSE; ResetEvent(hEvent2); } for(int x=0;x < 10000;x++) cout<<"o"; }; system("PAUSE"); return EXIT_SUCCESS; }
void thread (PVOID pvoid) { // HANDLE hEvent=(HANDLE)pvoid; while (true) { DWORD err=WaitForSingleObject(hEvent1,INFINITE); if (err==WAIT_FAILED) { cout<<GetLastError(); system("PAUSE"); } for(int i=0;i<repeat&&con1;i++) cout<<"."; } } ;
void thread2 (PVOID pvoid) { // HANDLE hEvent=(HANDLE)pvoid; // HANDLE hEvent2= CreateEvent(NULL,FALSE,FALSE,N_EVENT2); while (true) { DWORD err=WaitForSingleObject(hEvent2,INFINITE); if (err==WAIT_FAILED) { cout<<GetLastError(); system("PAUSE"); } for(int i=0;i<repeat&&con2;i++) cout<<"-"; } } ;
|
also besten dank LG |