1

Topic: Channels between flows

How in Qt to organize channels for a message exchange between flows? With queue and priorities? There is a flow which fulfills requests; to it other flows with requests address. Other flows can wait while the worker thread does not complete operation, or simply to give request and to receive any identifier to address later for result. Enough great volumes of the data can be result by the way. There should be a priority scheme that is if someone loaded a worker thread  tasks, and then someone sent high-priority - the high-priority should be fulfilled. There are any ready decisions in Qt for this purpose?

2

Re: Channels between flows

Hello, a9000, you wrote: A> there Should be a priority scheme that is if someone loaded a worker thread  tasks, and then someone sent high-priority - the high-priority should be fulfilled. In the tenth message of it  ( it appears) to you advise to take the Erlang and will be right.

3

Re: Channels between flows

Hello, a9000, you wrote: A> As in Qt to organize channels for a message exchange between flows? With queue and priorities? The first that got Google: http://qt-doc.ru/prioritety-potokov-v-qt.html http://qt-doc.ru/signalno-slotovye-soedineniya.html It in any literature on multi-threaded programming Qt speaks, in the documentation, books and so on. Yes, it is queue and priorities. If is interesting it is possible to esteem as signals are transferred in one flow, and as from one in another in more details. Thus usage of the metaobjective system is natural do the program more slowly, than at any optimized . But besides in Qt there are various modes of work in a multi-threaded mode. Personally I recommend to read simply help or at least head from any book on this subject.

4

Re: Channels between flows

Hello, velkin, you wrote: V> It in any literature on multi-threaded programming Qt speaks, in the documentation, books and so on. Yes, it is queue and priorities. If is interesting it is possible to esteem as signals are transferred in one flow, and as from one in another in more details. Thus usage of the metaobjective system is natural do the program more slowly, than at any optimized . But besides in Qt there are various modes of work in a multi-threaded mode. Personally I recommend to read simply help or at least head from any book on this subject. No, not "priorities of flows", it is not necessary for me. The ready component or a ready example with the code is necessary to me, able to do following 1. To launch a worker thread with my code 2. To accept "jobs" from other flows (it should be not mandatory Qt-shnye signals, and generally there can be all it not to Qt concerns, but should be ) 3. To save "jobs" in queue and  them as certain jobs 4. Each "job" should have a priority of performance for this queue 5. On termination of "job" performance to notify the sender was specific this job on that that all is ready Well type such, is very primitive TaskManager mgr; mgr.run ();//... int id1 = mgr.push_task (NORMAL, Data (...));//... int id2 = mgr.push_task (HIGH, Data (...) );//.... void onTaskFinished (int task_id) {}//...//my output agent of tasks inside TaskManager bool TaskManager:: processTask (const TaskData &data) {//... return true;//finished successfully} That to me of it is not clear - how better to do of all. That is whether to take Qt, or there are indirect libraries (the project is written on Qt so it is logical to look on Qt - but if for the given task there is something superficial indirect why and is not present). If Qt, whether that is enough for job transmission to use signals and slots, or not. How much signals and slots decelerate code performance in comparison with  without message passing between flows? In comparison with what decelerate? Clearly that when the user clicks the button and the unique task - that  is fulfilled. And if tasks arrive from  a file? How the cycle of reception of messages in a flow and their layouts in internal queue generally should be organized? The slot? How Qt will cause this slot if the flow is occupied at this time by calculations and is not in an operation cycle of messages? Whether suspends it at me a flow-sender? That is it is clear that any stupid method I it to make to a smog. But can eat already ready decisions in which all it is provided...

5

Re: Channels between flows

Hello, a9000, you wrote: A> That to me of it is not clear - how better to do of all. That is whether to take Qt, or there are indirect libraries (the project is written on Qt so it is logical to look on Qt - but if for the given task there is something superficial indirect why and is not present). Here my general answer to a subject that it is necessary to take Re: the Question on a multithreading for a C ++ the project the Author: velkin Date: 05.07.16. A> If Qt, whether that is enough for job transmission to use signals and slots, or not. How much signals and slots decelerate code performance in comparison with performance without message passing between flows? There not in flows business, the slot can be caused as function With ++, than it and is, and it is possible by means of the metaobjective system, that is as the slot. As Qt after code generation uses a pure C ++ after project start it is possible to look that he  in files and to count in how many it is all gets. But on the other hand from the programmer it is not necessary any special efforts for usage of this technology. A> the ready component or a ready example with the code is necessary to me, able to do following A> 5. On termination of "job" performance to notify the sender was specific this job on that that all is ready Once again short  the message under the link. Modes of work with execution flows in Qt: http://doc.qt.io/qt-5/threads-technologies.html 1) QThread: Low-Level API with Optional Event Loops 2) QThreadPool and QRunnable: Reusing Threads 3) Qt Concurrent: Using a High-level API To begin with it is better to read here it, there two approaches of the first mode of work with flows, by means of signals-SLOTS with usage moveToThread and by means of inheritance QThread with redefinition of a method (polymorphism). http://doc.qt.io/qt-4.8/qthread.html http://doc.qt.io/qt-5/qthread.html If does not suffice, in Qt there is a demo, in QtCreator or other editor it is possible to include search in files and to find under text QThread ready examples. It is possible to download to a heap of examples for books to the Breast-band, Blanshet/Sammerfild and so on. The second method is thread pool: http://doc.qt.io/qt-5/qthreadpool.html http://doc.qt.io/qt-5/qrunnable.html it is possible for your task approaches better, than QThread. As a matter of fact all too most, but in the form of a template of designing "thread pool". Gives thread pool for handling of the jobs presented normally in the form of queue. https://en.wikipedia.org/wiki/Thread_pool_pattern and the third method: http://doc.crossplatform.ru/qt/4.8.x/ht … rrent.html In the link the table http://doc.qt.io/qt-5/threads-technologies.html is painted more that it is necessary to select how to use and all something like that, but this one and too, so to say with . If there will be something more difficult, access to the same data from different flows, that is other classes, besides QThread or QThreadPool with QRunnable. http://doc.crossplatform.ru/qt/4.8.x/ht … reads.html I not so would like to retell by the own words when there is a normal documentation. We present application was started and it automatically has a principal flow of execution, differently anything would not work. And by means of QThread we can create still a flow or in case of other classes flows. And they start to work parallely, that is or on different kernels of the processor or on one, but there is no need behind it somehow especially to track. There are control functions, it is possible to stop this additional flow, to launch and so on. And here one of our functions will work in other flow, here there and the executable code will be placed. And even if it tightly hangs up, the main flow will work all the same, that is all will work. Depends on specific implementation, but as a whole it will be necessary to connect the slot of the beginning and a signal of end of operation to controlling program, it is possible to start on button click at which too there are actuating signals, on end the signal from a flow leaves the automatic machine. Is as standard examples showing how to make progress display, that is the additional flow works, transfers the message signals about progress, for example, to the core for display. Flows have identifiers how much I remember the same QtCreator it is all shows during a debug mode. In general I recommend to read the documentation, at least under links in this comment and all becomes clear. And it is even better to launch the code and there to experiment.

6

Re: Channels between flows

Hello, a9000, you wrote: A> As in Qt to organize channels for a message exchange between flows? With queue and priorities? I raised here this point in question - more than a year ago: https://rsdn.org/forum/cpp.applied/6492929 the Author: velkin Date: 05.07.16 P.S.  it is necessary to be defined precisely with the task and then to you ways of its decision will be more obvious. These ways can be a little: for example by means of Qt; std; boost; or Windows API. As alternative, application of indirect libraries of type OpenMP is possible: https://software.intel.com/ru-ru/blogs/ … 1/openmp-c

7

Re: Channels between flows

Hello, a9000, you wrote: Keywords in English: producer consumer c ++ threads It about the task in general, priorities and Qt - details. It is possible to begin from here: Producer-consumer problem

8

Re: Channels between flows

Hello, AlexGin, you wrote: AG> These ways can be a little: for example by means of Qt; std; boost; or Windows API. AG>... Absolutely not very well, what  to use for operation with flows. A question about queue with priorities.

9

Re: Channels between flows

Hello, a9000, you wrote: A> there Should be a priority scheme that is if someone loaded a worker thread  tasks, and then someone sent high-priority - the high-priority should be fulfilled. A> there are any ready decisions in Qt for this purpose? Ready is not present, at you dedicated enough task. Once I did so. Certainly, algorithm not super exact, but enough simple in implementation. On fighting servers till now works on hurrah. We admit at us 8 kernels then it is necessary to create a pool from 8 flows, conditionally divided on two pools (on 5 and 3 flows, accordingly). "Long" tasks (with low priority) go only on the second pool (flows 6-8). If there all flows are occupied, the task is put in  queue and its beret  the released flow from the second pool (6-8 flows)." Fast "tasks go on the following logic: If in the first pool (1-5 flow) there are the free flows - the task goes there. Otherwise the free flow in the second pool (6-8) is searched. If the free flows are not present, the task is put in high-priority queue and its beret the first released flow (an important point - from any pool). A little chaotically it turned out, but I think that is clear. Concerning results - it is better to put all in a separate cache. And how already to give - at once or on demand - it is not important. Do not forget that Qt containers support all COW. I.e. the variant with QHash <Key, QByteArray> will be fast enough.