IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Threads & Processus C++ Discussion :

erreur bizarre selon execution sur machine multicoeurs ou non


Sujet :

Threads & Processus C++

  1. #1
    Membre régulier Avatar de lyxthe
    Profil pro
    Inscrit en
    Septembre 2006
    Messages
    115
    Détails du profil
    Informations personnelles :
    Âge : 40
    Localisation : France

    Informations forums :
    Inscription : Septembre 2006
    Messages : 115
    Points : 90
    Points
    90
    Par défaut erreur bizarre selon execution sur machine multicoeurs ou non
    Bonjour à tous, je vous soummet un problème bizar que je rencontre, j'aimerai savoir si quelqu'un peut m'eclairer. J'ai fait un petit programme qui execute 12 thread (je le pose ci après)

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    #include <boost/thread/thread.hpp>
    #include <boost/bind.hpp>
     
     
    using namespace std;
     
    void fonct(int num){
    	cout << "thread " << num << endl;
    }
     
    int main(){
    	int i=0;
    	int j=0;
    	boost::thread_group groupe;
    	for(i=0;i<5;i++){
    		cout << "debut boucle " << i << ":" << endl;
    		for(j=1;j<12;j++){
    			groupe.create_thread(boost::bind(fonct,j));
    		}
    		fonct(0);
    		cout << "a la fin du fonct" << endl;
    		cout << "en attente du join.all " << endl;
    		groupe.join_all();
    		cout<< "apres le join.all" << endl;
    	}
    	return 0;
    }
    Ce programme executé sur une machine monocoeur fonctionne jusqu'au bout, mais testé sur une machine 4 coeurs et sur une autre 12 coeurs cela me fait une erreur segmentation fault, je vous met les traces sur les trois machine ci après :

    pour la 12 coeurs et la 4 coeurs (même trace)
    debut boucle 0:
    thread 1
    thread 2
    thread 3
    thread 4
    thread 5
    thread 6
    thread 7
    thread 8
    thread 9
    thread 10
    thread 11
    thread 0
    a la fin du fonct
    en attente du join.all
    apres le join.all
    debut boucle 1:
    thread 1
    thread 2
    thread 3
    thread 4
    thread 5
    thread 6
    thread 7
    thread 8
    thread 9
    thread 10
    thread 11
    thread 0
    a la fin du fonct
    en attente du join.all
    Erreur de segmentation
    pour la mono coeur
    debut boucle 0:
    thread 1
    thread 2
    thread 3
    thread 4
    thread 5
    thread 6
    thread 7
    thread 8
    thread 9
    thread 10
    thread 11
    thread 0
    a la fin du fonct
    en attente du join.all
    apres le join.all
    debut boucle 1:
    thread 1
    thread 2
    thread 3
    thread 4
    thread 5
    thread 6
    thread 7
    thread 8
    thread 9
    thread 10
    thread 11
    thread 0
    a la fin du fonct
    en attente du join.all
    apres le join.all
    debut boucle 2:
    thread 1
    thread 2
    thread 3
    thread 4
    thread 5
    thread 6
    thread 7
    thread 8
    thread 9
    thread 10
    thread 11
    thread 0
    a la fin du fonct
    en attente du join.all
    apres le join.all
    debut boucle 3:
    thread 1
    thread 2
    thread 3
    thread 4
    thread 5
    thread 6
    thread 7
    thread 8
    thread 9
    thread 10
    thread 11
    thread 0
    a la fin du fonct
    en attente du join.all
    apres le join.all
    debut boucle 4:
    thread 1
    thread 2
    thread 3
    thread 4
    thread 5
    thread 6
    thread 7
    thread 8
    thread 9
    thread 10
    thread 11
    thread 0
    a la fin du fonct
    en attente du join.all
    apres le join.all
    Appuyez sur la touche «*Entrée*» pour continuer*!
    Si quelqu'un a une idée d'où peut venir ce segmentation fault, s'il vous plait, moi je ne comprend pas.

    Merci

  2. #2
    zul
    zul est déconnecté
    Membre éclairé Avatar de zul
    Profil pro
    Inscrit en
    Juin 2002
    Messages
    498
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juin 2002
    Messages : 498
    Points : 699
    Points
    699
    Par défaut
    std::cout n'est pas thread-safe, il faut le proteger avec une section critique qui va bien. Je suppose qu'il se passe un truc malheureux dans le cas multi-core (genre plusieurs cpus qui modifient en meme temps l'objet).

  3. #3
    Membre régulier Avatar de lyxthe
    Profil pro
    Inscrit en
    Septembre 2006
    Messages
    115
    Détails du profil
    Informations personnelles :
    Âge : 40
    Localisation : France

    Informations forums :
    Inscription : Septembre 2006
    Messages : 115
    Points : 90
    Points
    90
    Par défaut
    Je ne sais pas trop, au moment où le segmentation fault survient, tous les threads sont terminés, il n'y a pas de cout à faire, c'est visiblement dans le join.all qu'il y a un problème. Est-il possible que le soucis vienne de la librairie boost_thread ? Si c'etait le cas, me faut-il changer le sujet de forum ? Quelqu'un a-t-il une autre idée, ou alors est-ce vraiment la faut des cout alors que normalement plus aucun n'est supposé s'exécuter ?

  4. #4
    Membre régulier Avatar de lyxthe
    Profil pro
    Inscrit en
    Septembre 2006
    Messages
    115
    Détails du profil
    Informations personnelles :
    Âge : 40
    Localisation : France

    Informations forums :
    Inscription : Septembre 2006
    Messages : 115
    Points : 90
    Points
    90
    Par défaut
    Si ça peut aider à la comprehension je vous joins la trace du debuggage :
    le$ gdb ./a12g0et1.out
    GNU gdb 6.8-debian
    Copyright (C) 2008 Free Software Foundation, Inc.
    License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
    This is free software: you are free to change and redistribute it.
    There is NO WARRANTY, to the extent permitted by law. Type "show copying"
    and "show warranty" for details.
    This GDB was configured as "x86_64-linux-gnu"...
    (gdb) r
    Starting program: /PATH_TO_FILE/a12g0et1.out
    [Thread debugging using libthread_db enabled]
    debut boucle 0:
    [New Thread 0x7fb24ebc26f0 (LWP 4696)]
    [New Thread 0x4115f950 (LWP 4699)]
    thread 1
    [Thread 0x4115f950 (LWP 4699) exited]
    [New Thread 0x40848950 (LWP 4700)]
    thread 2
    [Thread 0x40848950 (LWP 4700) exited]
    [New Thread 0x41960950 (LWP 4701)]
    thread 3
    [Thread 0x41960950 (LWP 4701) exited]
    [New Thread 0x42161950 (LWP 4703)]
    thread 4
    [Thread 0x42161950 (LWP 4703) exited]
    [New Thread 0x42962950 (LWP 4704)]
    thread 5
    [Thread 0x42962950 (LWP 4704) exited]
    [New Thread 0x43163950 (LWP 4705)]
    thread 6
    [Thread 0x43163950 (LWP 4705) exited]
    [New Thread 0x43964950 (LWP 4706)]
    thread 7
    [Thread 0x43964950 (LWP 4706) exited]
    [New Thread 0x44165950 (LWP 4708)]
    thread 8
    [Thread 0x44165950 (LWP 4708) exited]
    [New Thread 0x44966950 (LWP 4709)]
    thread 9
    [Thread 0x44966950 (LWP 4709) exited]
    [New Thread 0x45167950 (LWP 4711)]
    thread 10
    [Thread 0x45167950 (LWP 4711) exited]
    [New Thread 0x45968950 (LWP 4712)]
    thread thread 011

    a la fin du fonct
    [Thread 0x45968950 (LWP 4712) exited]
    en attente du join.all
    apres le join.all
    debut boucle 1:
    [New Thread 0x45968950 (LWP 4713)]
    thread 1
    [Thread 0x45968950 (LWP 4713) exited]
    [New Thread 0x45167950 (LWP 4714)]
    thread 2
    [Thread 0x45167950 (LWP 4714) exited]
    [New Thread 0x44966950 (LWP 4715)]
    thread 3
    [Thread 0x44966950 (LWP 4715) exited]
    [New Thread 0x44165950 (LWP 4716)]
    thread 4
    [Thread 0x44165950 (LWP 4716) exited]
    [New Thread 0x411da950 (LWP 4717)]
    thread 5
    [Thread 0x411da950 (LWP 4717) exited]
    [New Thread 0x41f0e950 (LWP 4718)]
    thread 6
    [Thread 0x41f0e950 (LWP 4718) exited]
    [New Thread 0x4270f950 (LWP 4720)]
    thread 7
    [Thread 0x4270f950 (LWP 4720) exited]
    [New Thread 0x42f10950 (LWP 4721)]
    thread 8
    [Thread 0x42f10950 (LWP 4721) exited]
    [New Thread 0x409ae950 (LWP 4722)]
    thread 9
    [Thread 0x409ae950 (LWP 4722) exited]
    [New Thread 0x43711950 (LWP 4723)]
    thread 10
    [Thread 0x43711950 (LWP 4723) exited]
    [New Thread 0x46169950 (LWP 4724)]
    thread 11
    thread 0
    a la fin du fonct
    [Thread 0x46169950 (LWP 4724) exited]
    en attente du join.all

    Program received signal SIGSEGV, Segmentation fault.
    [Switching to Thread 0x7fb24ebc26f0 (LWP 4696)]
    0x00007fb24d8932a2 in __deallocate_stack () from /lib/libpthread.so.0
    (gdb) bt
    #0 0x00007fb24d8932a2 in __deallocate_stack () from /lib/libpthread.so.0
    #1 0x00007fb24d8946da in pthread_join () from /lib/libpthread.so.0
    #2 0x00007fb24e7b2b2e in boost::thread::join ()
    from /usr/lib/libboost_thread-gcc42-mt-1_34_1.so.1.34.1
    #3 0x00007fb24e7b2f49 in boost::thread_group::join_all ()
    from /usr/lib/libboost_thread-gcc42-mt-1_34_1.so.1.34.1
    #4 0x00000000004026d5 in main () at testproc12.cpp:24
    (gdb)

  5. #5
    Expert éminent sénior
    Avatar de Médinoc
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Septembre 2005
    Messages
    27 381
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 40
    Localisation : France

    Informations professionnelles :
    Activité : Développeur informatique
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Septembre 2005
    Messages : 27 381
    Points : 41 582
    Points
    41 582
    Par défaut
    Cette fois-ci, on dirait bien que c'est boost_thread qui plante sur le join_all.

    ...Ou bien, quelque chose a corrompu le tas avant.

  6. #6
    Expert confirmé

    Homme Profil pro
    Développeur informatique
    Inscrit en
    Septembre 2007
    Messages
    1 895
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 48
    Localisation : France, Bouches du Rhône (Provence Alpes Côte d'Azur)

    Informations professionnelles :
    Activité : Développeur informatique
    Secteur : High Tech - Opérateur de télécommunications

    Informations forums :
    Inscription : Septembre 2007
    Messages : 1 895
    Points : 4 551
    Points
    4 551

  7. #7
    Expert éminent sénior
    Avatar de Luc Hermitte
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Août 2003
    Messages
    5 281
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Haute Garonne (Midi Pyrénées)

    Informations professionnelles :
    Activité : Développeur informatique
    Secteur : Aéronautique - Marine - Espace - Armement

    Informations forums :
    Inscription : Août 2003
    Messages : 5 281
    Points : 11 029
    Points
    11 029
    Par défaut
    La même chose sans les traces donne quoi ?

Discussions similaires

  1. Réponses: 1
    Dernier message: 01/12/2014, 09h41
  2. Réponses: 5
    Dernier message: 30/11/2009, 10h40
  3. erreur bizarre en java sur les codes contenant <TYPE>
    Par doderic dans le forum Langage
    Réponses: 6
    Dernier message: 23/08/2009, 18h52
  4. execution sur l'emulateur mais non pas sur le Pocket PC
    Par inter_amine dans le forum Windows Mobile
    Réponses: 2
    Dernier message: 08/06/2007, 09h35
  5. Erreur d'execution sur accès base acces en VB6
    Par gino911 dans le forum Access
    Réponses: 4
    Dernier message: 06/03/2006, 13h22

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo