Le Wed, 13 Apr 2005 01:10:59 +0200
manioul <[EMAIL PROTECTED]> a �crit:
> Le mardi 12 avril 2005 � 23:17 +0200, Fran�ois Boisson a �crit :
> [...]
> > > Que dit `ps fax` ?
> >
> > 21389 pts/8 Ss 0:00 \_ bash -i
> > 21544 pts/8 S+ 0:00 \_ logrecept -y
> > 21546 pts/8 S+ 0:00 \_ logrecept -y
> > 21547 pts/8 S+ 0:02 \_
> > logrecept-y
> >
> > A priori, il est normal que le dernier soit celui qui bosse, il
> > fabrique les requ�tes SQL et les ex�cute, le ma�tre se contente
> > (comme tous les patrons (!)) de recevoir les paquets et de
> > transmettre...
> Tu as bien v�rifi� dans ton code si tu es fils ou parent? Il semble
> que tes processus fils fork...
Je confirme bien, un thread cr�e, 3 processus fils l'un de l'autre:
Le petit fils est le thread (il disparait � la fin du thread)
Le p�re est le processus maitre
Le fiston semble �tre un processus qui g�re les mutex et autres conds,
j'ai test� �a avec le programme suivant en le modifiant pour geler ou
non l'arr�t.
Fran�ois Boisson
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <string.h>
#include <stdio.h>
#include <signal.h>
#include <arpa/inet.h>
#include <netdb.h>
#include <unistd.h>
#include <time.h>
#include <pwd.h>
#include <sys/ioctl.h>
#include <errno.h>
#include <signal.h>
#include <pthread.h>
#include <malloc.h>
pthread_mutex_t mutex_file = PTHREAD_MUTEX_INITIALIZER;
pthread_mutex_t mutex_boulot = PTHREAD_MUTEX_INITIALIZER;
pthread_cond_t cond_boulot = PTHREAD_COND_INITIALIZER;
pthread_mutex_t mutex_fini = PTHREAD_MUTEX_INITIALIZER;
pthread_cond_t cond_fini = PTHREAD_COND_INITIALIZER;
pthread_t tache;
int STOP=0;
void rajoute()
{
printf("Hop un coup de tache\n");
pthread_mutex_lock(& mutex_boulot);
pthread_cond_signal(& cond_boulot);
pthread_mutex_unlock(& mutex_boulot);
}
void * tache_de_fond(queud)
void *queud;
{
while(STOP==0)
{
printf("Salut c'est le thread\n");
pthread_mutex_lock(& mutex_boulot);
pthread_cond_wait(& cond_boulot,& mutex_boulot);
pthread_mutex_unlock(& mutex_boulot);
}
printf("Stop Thread\n");
pthread_mutex_lock(& mutex_fini);
pthread_cond_signal(& cond_fini);
pthread_mutex_unlock(& mutex_fini);
printf("Retour Thread\n");
pthread_exit(NULL);
}
void arret(inutile)
int inutile;
{
int i,j,k,l;
printf("STOP: ^C arriv�\n");
pthread_mutex_lock(& mutex_boulot);
pthread_cond_signal(& cond_boulot);
pthread_mutex_unlock(& mutex_boulot);
if (pthread_equal(tache,pthread_self()))
{
printf("Hmm, CtrlC sur le Thread\n");
}
else
{
printf("On arrete le thread!\n");
pthread_mutex_lock(& mutex_fini);
printf("Attente du thread\n");
STOP=1;
/* attente de la fin du thread */
pthread_mutex_lock(& mutex_boulot);
pthread_cond_signal(& cond_boulot);
pthread_mutex_unlock(& mutex_boulot);
pthread_cond_wait(& cond_fini,& mutex_fini);
pthread_mutex_unlock(& mutex_fini);
printf("Ahah thread fini?\n");
pthread_join(tache,NULL);
/* on arrete l'envoi des logs */
printf("Thread fini!\n");
exit(0);
}
}
main(argc,argv)
int argc;
char **argv;
{
/* programmation d�gueulasse, ramassis de variables, tant pis */
signal(SIGINT,arret);
/* lancement du thread */
pthread_create(&tache,NULL,tache_de_fond,NULL);
while (1==1)
{
pthread_mutex_lock(& mutex_boulot);
pthread_cond_signal(& cond_boulot);
pthread_mutex_unlock(& mutex_boulot);
}
exit(0);
}
--
Pensez � lire la FAQ de la liste avant de poser une question :
http://wiki.debian.net/?DebianFrench
Pensez � rajouter le mot ``spam'' dans vos champs "From" et "Reply-To:"
To UNSUBSCRIBE, email to [EMAIL PROTECTED]
with a subject of "unsubscribe". Trouble? Contact [EMAIL PROTECTED]