c++ - Signal and Slot vs Multithreading in Boost Library -


I have gone through similar questions on stackoverflow, but still no good answer can be found:


  • I am amazed at how this signal / slot has been achieved. Question 1: From the following code, the sign is connected to two functions (hello) and the World (), and it seems that the function is called in sequential manner, which also means that , A function (hello) should be completed before going to another function (world)? => Single Thread Program

    Question 2: What is anyway to enable multi-threaded signal / slots? (=> World () will start immediately, no need to wait to meet Namaskar ().) Or if it is not recommended, will you tell me why?

    :

      Stretch Hello {zero operator () () const {std :: cout & lt; & Lt; "Hello";} }; Structure World {zero operator () () const {std :: cout & lt; & Lt; ", world!" & Lt; & Lt; Std :: endl;}}; Promotion: Indication & lt; Void () & gt; signature; Sig.connect (hello ()); Sig.connect (world ()); Sig ();  

    Output: Hello, World!

    Question 1:
    Calls are ordering Indicators are internal, very simple :

      foreach connection: call handler  

    So you do not want to block in the handler for a long time. If you need to do more work, you can take it from there, for example by making a thread for it.

    Question 2:
    To promote signals, 1 thread is not even safe; Signal 2 is, but still have serialized calls. As the signals are primarily used for event handling, in reality those who conduct themselves do not have the usual style to do more work.
    Thus there is no real advantage in calling them 'parallel', profit generally overhead essential thread exploration.


    Comments

    Popular posts from this blog

    asp.net - Javascript/DOM Why is does my form not support submit()? -

    sockets - Delphi: TTcpServer, connection reset when reading -

    javascript - Classic ASP "ExecuteGlobal" statement acting differently on two servers -