Visualizzazione dei risultati da 1 a 4 su 4

Discussione: [C++] Printf e Thread

  1. #1

    [C++] Printf e Thread

    Save a tutti..
    eccomi con l'ennesimo quesito:
    Ultimamente ho sperimentato la programmazione multithreading e quindi mutex semafori etc... ho pensato che siccome la printf scrive su sdtin, ci sia il bisongo di usare un semaforo anche per l'uso della printf... è così?

    grazie a tutti... =)

  2. #2
    Utente di HTML.it L'avatar di shodan
    Registrato dal
    Jun 2001
    Messaggi
    2,381
    Usando le librerie multithreading, la printf ha già all'interno il sistema di sincronizzazione. Per le prove che facevo tempo fa usavo proprio la printf per stampare a video.
    Gli stream (cout) devono essere sincronizzati a causa degli operatori di inserimento che non sono thread safe.
    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.

  3. #3
    perfetto.... e sai se anche puts() è threadsafe? perchè di solito uso quella per fare il debug...

    grazie mille!

  4. #4
    Utente di HTML.it L'avatar di shodan
    Registrato dal
    Jun 2001
    Messaggi
    2,381
    Non lo so ma penso di si.
    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 © 2025 vBulletin Solutions, Inc. All rights reserved.