Visualizzazione dei risultati da 1 a 4 su 4
  1. #1

    [c] problemi con CreateThread()

    ho creato un server che tramite la funzione
    codice:
    CreateThread(NULL,0,(LPTHREAD_START_ROUTINE) funzione, (LPVOID) clientsd, 0, &ThreadId);
    invia più client alla function funzione, il problema è che fin quando il primo client che accede a funzione è l'unico ad utilizzare la funzione tutto va bene, mentre se inizia ad accedere un secondo client alla function funzione e la usa ecco che il codice all'interno della function inizia a diventare ricorsivo, cioè il simbolo del compilatore visual studio che indica la posizione thread inizia a muoversi avanti e indietro.

    sapreste dirmi perchè?

  2. #2
    Utente di HTML.it L'avatar di Stoicenko
    Registrato dal
    Feb 2004
    Messaggi
    2,254
    bè proprio perchè più thread accedono alla stessa funzione essi si trovano allo stesso momento in punti differenti.. fare debug "passo-passo" di una funzione multithread è molto complicato..

  3. #3
    no anche se il primo client termina la funzione si verifica lo stesso il problema quando entra il secondo client, ho letto che un thread ha uno stack forse è la condivisione di questo stack che crea tutto ciò, allora mi chiedo è possibile che ogni client abbia un proprio stack?

  4. #4
    Utente di HTML.it L'avatar di shodan
    Registrato dal
    Jun 2001
    Messaggi
    2,381
    Lo Stack è univoco per thread. E' l'heap che è condiviso.
    E comunque è bene usare la _beginthreadex in C.

    http://msdn.microsoft.com/en-us/library/ms682453(VS.85).aspx
    ...
    A thread in an executable that calls the C run-time library (CRT) should use the _beginthreadex and _endthreadex functions for thread management rather than CreateThread and ExitThread; this requires the use of the multi-threaded version of the CRT. If a thread created using CreateThread calls the CRT, the CRT may terminate the process in low-memory conditions.
    This code and information is provided "as is" without warranty of any kind, either expressed
    or implied, including but not limited to the implied warranties of merchantability and/or
    fitness for a particular purpose.

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2024 vBulletin Solutions, Inc. All rights reserved.