1

Topic: How now write multi-threaded applications on a C ++?

It was required to add a multithreading in the program. I did it earlier (on Windows) using about such code: DWORD WINAPI threadFunction (PVOID param) {//at first we write stream function DWORD result = 0;//do something... return result;} _beginthreadex (..., threadFunction...);//we launch with the help With ++ run-time library functions As it is accepted to do it after a C output ++ 11? Using std:: thread? Or any boost-ovskaja the library will be more convenient? And still a question - as affairs with programming of multi-threaded applications on pluses after an output With ++ 11 generally are? Whether there was a programming of multi-threaded applications on pluses same convenient as, for example, in Java?

2

Re: How now write multi-threaded applications on a C ++?

In Google, ,   full educational literature, free courses and if you are not capable to self-training and finding of answers to questions - such programmer and for nothing it is necessary to nobody, you now in vain make efforts mastering With ++ https://www.youtube.com/results?search_ … 1%81%D1%8B https://www.youtube.com/user/CppCon/videos https://www.youtube.com/channel/UCNuItl … oBg/videos https://www.youtube.com/user/MeetingCPP/videos is __ answers to your questions if once again come with a question that where as why, the troll means you

3

Re: How now write multi-threaded applications on a C ++?

Hello, Maxim Rogozhin, you wrote: > It was required to add a multithreading in the program. For what purpose? > And still a question - as affairs with programming of multi-threaded applications on pluses after an output With ++ 11 generally are? Convenience of programming of multi-threaded applications strongly depends on at what level you work with a multithreading. If at level of bare threads, mutex, condition variables or atomic (with manual implementations lock-free data structures) it is sweat, a pain and blood. If the ready tools giving to you more high levels of abstraction (like fork-join, work stealing, tasks, CSP-channels, actors and so forth), all much better, easier and faster are used. Whether MP> there was a programming of multi-threaded applications on pluses same convenient as, for example, in Java? With such stoppings at once in comp.flame.

4

Re: How now write multi-threaded applications on a C ++?

Hello, so5team, you wrote: >> It was required to add a multithreading in the program. S> for what purpose? Well here if without particulars: I read in parts very big files, I assort them, and I search in them for the certain information as found more to me this file I am not necessary also it I close. Not to process files by turns I and I want to make that each file was processed in a flow (while the next portion of a file other flows is read can be fulfilled, at the expense of it the gain in time should be). >> And still a question - as affairs with programming of multi-threaded applications on pluses after an output With ++ 11 generally are? S> Convenience of programming of multi-threaded applications strongly depends on at what level you work with a multithreading. If at level of bare threads, mutex, condition variables or atomic (with manual implementations lock-free data structures) it is sweat, a pain and blood. If the ready tools giving to you more high levels of abstraction (like fork-join, work stealing, tasks, CSP-channels, actors and so forth), all much better, easier and faster are used. Well adding to standard means of a C ++ std:: thread, std:: mutex, std:: condition_variable etc. in any way did not refine a situation in comparison with, whether that was to With ++ 11 that?

5

Re: How now write multi-threaded applications on a C ++?

Hello, Maxim Rogozhin, you wrote: S>> For what purpose? > Well here if without particulars: I read in parts very big files, I assort them, and I search in them for the certain information as found more to me this file I am not necessary also it I close. > not to process files by turns I and I want to make that each file was processed in a flow (while is read the next portion of a file other flows can be fulfilled, at the expense of it a gain in time should be). And if at you 100500 files you create 100500 flows? > Well adding to standard means of a C ++ std:: thread, std:: mutex, std:: condition_variable etc. in any way did not refine a situation in comparison with, whether that was to With ++ 11 that? Unless that earlier all this economy needed to be dragged in the project together with 3rd party libraries, and now it is accessible from a box. But in essence changed nothing.

6

Re: How now write multi-threaded applications on a C ++?

Hello, Maxim Rogozhin, you wrote: > Hello, so5team, you wrote: > Well here if without particulars: I read in parts very big files, I assort them, and I search in them for the certain information as found more to me this file I am not necessary also it I close. Here much depends on your disk system, from its throughput and ability to read simultaneously it is a lot of files. > not to process files by turns I and I want to make that each file was processed in a flow (while is read the next portion of a file other flows can be fulfilled, at the expense of it a gain in time should be). In Windows is overlaped reading while it reads you process that that already is. > Well adding to standard means of a C ++ std:: thread, std:: mutex, std:: condition_variable etc. in any way did not refine a situation in comparison with, whether that was to With ++ 11 that? What problems were such and remained. But  it certainly changed - new problems were added

7

Re: How now write multi-threaded applications on a C ++?

Hello, Maxim Rogozhin, you wrote: > not to process files by turns I and I want to make that each file was processed in a flow (while is read the next portion of a file other flows can be fulfilled, at the expense of it a gain in time should be). If you are going to read/write simultaneously some files most likely you will receive not a scoring, and the big loss. At least, on mechanical disks.

8

Re: How now write multi-threaded applications on a C ++?

Hello, Maxim Rogozhin, you wrote: the main plus of usage std:: - you will receive the kros-platform code plus esteem about , they  to work dataful of different flows without  but if the task on handling of files as correctly already told, it is not necessary to read files from  flows, it can lower productivity. To process - yes, but not to read.

9

Re: How now write multi-threaded applications on a C ++?

Hello, Pzz, you wrote: Pzz> If you are going to read/write simultaneously some files most likely you will receive not a scoring, and the big loss. At least, on mechanical disks. Well certainly, no. To a disk with NQ the pack of commands falls down record, and it scatters them on itself(himself) as to it is more visible.

10

Re: How now write multi-threaded applications on a C ++?

Hello, Glory, you wrote: Pzz>> If you are going to read/write simultaneously some files most likely you will receive not a scoring, and the big loss. At least, on mechanical disks. Well certainly, no. To a disk with NQ the pack of commands falls down record, and it scatters them on itself(himself) as to it is more visible. Dreams-dreams

11

Re: How now write multi-threaded applications on a C ++?

Hello, Maxim Rogozhin, you wrote: > It was required to add a multithreading in the program. I did it earlier (on Windows) using about such code: > > DWORD WINAPI threadFunction (PVOID param) {//at first we write stream function > DWORD result = 0; >//do something... > return result; >} > _beginthreadex (..., threadFunction...);//we launch with the help With ++ run-time library functions > > As it is accepted to do it after a C output ++ 11? Using std:: thread? Or any boost-ovskaja the library will be more convenient? In MINGW (gcc + win32api + M $ libc) there is a simulation libpthreads.

12

Re: How now write multi-threaded applications on a C ++?

Hello, Maxim Rogozhin, you wrote: > And still a question - as affairs with programming of multi-threaded applications on pluses after an output With ++ 11 generally are? Read Concurrence in Action, all questions disappear. Is in Russian and is free".

13

Re: How now write multi-threaded applications on a C ++?

Hello, Maxim Rogozhin, you wrote: > And still a question - as affairs with programming of multi-threaded applications on pluses after an output With ++ 11 generally are? std:: thread... <thread>

14

Re: How now write multi-threaded applications on a C ++?

Hello, Maxim Rogozhin, you wrote: > As it is accepted to do it after a C output ++ 11? Using std:: thread? Or any boost-ovskaja the library will be more convenient? Since a C ++ 11 there was usage possibility  templates that decoupled hands to designers of standard library a little and there was a possibility of floppy implementation in it of many new features. boost whenever possible it is not necessary to apply in the presence of similar functionality in standard library. It is too much boost normally pulls behind itself. Operation with std:: thread is very similar to implementation of flows in POSIX, almost similar dial-up of functionality. In something even it is more convenient. Start: std:: thread thr = std:: thread (func, params...) ; Here in quality func static function by which control in a new flow, further the parameter list which it is necessary to transfer in it will be transferred is underlined. It is possible to use a lambda-function (a C ++ 14) then directly inline it is possible to specify a call, for example, function-member of a current copy of a class. std:: thread thr = std:: thread ([and] () {ReadThread ();} ); join () - end waiting, get_id () - to receive id a flow native_handle () - to receive  a flow descriptor detach () - to untie a flow from process, it is convenient before violent  (aka TerminateThread) In case of an output std:: thread for visibility limits (if object on a stack) or at clearing of object in case of storage in the form of the pointer, happens violent  a flow to a call assert in the debug-version if there was no preliminary call detach (). By means of the mechanism std:: promise/std:: future it is possible to get a flag which, using standard library,  about waiting of voluntary end of a flow within set  before its violent  (std::promise<bool>::set_value_at_thread_exit (true)). With the help a lambda of functions and the same mechanism std:: future/std:: async it is possible to launch asynchronously the flow code directly in a body of current function (inside a lambda), for example std:: future <int> result = std:: async (std:: launch: :async, [and] () {puts ("In new thread"); return 0;}); > And still a question - as affairs with programming of multi-threaded applications on pluses after an output With ++ 11 generally are? Whether there was a programming of multi-threaded applications on pluses same convenient as, for example, in Java? The programming of multi-threaded applications similar Java on  with similar API, I implemented many years ago independently in the form of static  without any Cs ++ 11. The C ++ 11 simply standardizes  API. It is worse WinAPI, but it is better than a POSIX-variant ().

15

Re: How now write multi-threaded applications on a C ++?

Hello, Glory, you wrote: Hello, Pzz, you wrote: Pzz>> If you are going to read/write simultaneously some files most likely you will receive not a scoring, and the big loss. At least, on mechanical disks. Well certainly, no. To a disk with NQ the pack of commands falls down record, and it scatters them on itself(himself) as to it is more visible. Proceeding from the task description - readings of set of huge files that if these files on one disk that all rests against restriction of throughput of reading/record of a disk and additional flows import still complexity of switching of a context of the task between flows and therefore increase program performance.