pouët.net

Random thread image

category: general [glöplog]
 
BB Image
added on the 2007-09-06 15:36:14 by kusma kusma
BB Image
added on the 2007-09-06 15:45:10 by xernobyl xernobyl
BB Image
added on the 2007-09-06 16:04:05 by hornet hornet
BB Image
added on the 2007-09-06 16:23:08 by Optimus Optimus
BB Image
added on the 2007-09-06 16:26:00 by xernobyl xernobyl
#include <stdio.h>
#include <conio.h>
#include <windows.h>
#include <time.h>

/* Definición de variables globales */
HANDLE g_hMutex = NULL;

/* Función correspondiente al primer hilo */
DWORD HiloUno(LPVOID p){
BOOL fDone = FALSE;
DWORD dw;

while(!fDone){
/* Esperamos a que el mútex esté libre */
if ((dw = WaitForSingleObject(g_hMutex, INFINITE)) == WAIT_OBJECT_0)
{
/* Código del hilo 1 */

/*Liberamos el mútex */
ReleaseMutex(g_hMutex);
} else {
break; /* Se ha producido un error */
}
}
return(0);
}

/* Función correspondiente al segundo hilo */
DWORD HiloDos(LPVOID p){
BOOL fDone = FALSE;
DWORD dw;

while(!fDone){
/* Esperamos a que el mútex esté libre */
if ((dw = WaitForSingleObject(g_hMutex, INFINITE)) == WAIT_OBJECT_0)
{
/* Código del hilo 1 */

/*Liberamos el mútex */
ReleaseMutex(g_hMutex);
} else {
break; /* Se ha producido un error */
}
}
return(0);
}

/* Programa principal */
int main (int argv, char *argc[]){
/*DWORD HiloUno;
DWORD HiloDos;*/
HANDLE hThread[2];
DWORD IDThread[2];

/* Creamos el mútex sin ser propietarios y sin nombre */
g_hMutex = CreateMutex(NULL, FALSE, NULL);

/* Creamos los hilos secundarios */
hThread[0] = CreateThread(NULL,0,(LPTHREAD_START_ROUTINE) HiloUno,NULL,0,&IDThread[0]);
hThread[1] = CreateThread(NULL,0,(LPTHREAD_START_ROUTINE) HiloDos,NULL,0,&IDThread[1]);

/* Esperamos la finalización de los hilos secundarios */
WaitForMultipleObjects(2,hThread,TRUE,INFINITE);

/* Cerramos los descriptores de los hilos */
CloseHandle(hThread[0]);
CloseHandle(hThread[1]);

/* Eliminamos el mútex */
CloseHandle(g_hMutex);

return 0;
}
added on the 2007-09-06 16:38:15 by stage7 stage7
BB Image
added on the 2007-09-13 15:54:41 by dissent dissent
BB Image
added on the 2007-09-13 16:31:54 by bdk bdk
BB Image
added on the 2007-09-13 17:50:30 by xernobyl xernobyl

login