26

Re: How to write the code consuming about 10 % of the processor?

Hello, Terix, you wrote: T> Hello, SkyDance, you wrote: SD>> Not more slowly, and with more low priority. That did not hinder to be played. T> is not present, more slowly. It is possible to consider that we will have 2 flows. One slow, and another - normal. It is possible still here so - for example at me 4 logical kernels. That I see in Windows. If to click with the right mouse button in the task list the necessary process that except to expose low priority it is possible to fix it for 1 and only 1 kernel. I.e. in my case  only 25 % - and 75 % freely for games and the browser Thus brake nothing also the fan not  - check up if do not trust. For certain it can be made and .

27

Re: How to write the code consuming about 10 % of the processor?

T> Is not present, more slowly. It is possible to consider that we will have 2 flows. One slow, and another - normal. Understood nothing. You want, that it was possible "to be played without brakes", an essence to give a priority to games. And when games are not played, it is possible to carry out the rated task. Or you want other? Then formulate the task was more specific.

28

Re: How to write the code consuming about 10 % of the processor?

T> If simply to pass cycles entrance in while all the same  system on 100 %, and it not that that is necessary for us. Would Remain sleep like. Not sleep (), and wait (). Read about synchronization.

29

Re: How to write the code consuming about 10 % of the processor?

Hello, Masterspline, you wrote: M> At last you wrote, in what the task actually consists. In what the task I consists wrote from the very beginning. Here I offered one of variants that it can mean in practice. Still here - any graphic interface, it not  100 % even if there something happens though on idea should. There too, how in the decision offered by you 2 flows? M> in such situation I would make, that the calculation flow fell asleep after each frame and he was awoken on the timer with other flow. As a matter of fact supervised sleep (). If accuracy it is finite on another in any way is necessary. Understood you, thanks. M> schedulers, priorities and sleep () here generally at anything. Schedulers and priorities probably it is valid there is nothing, and sleep () in general does that you offered, only without an additional flow and it is less predicted.

30

Re: How to write the code consuming about 10 % of the processor?

Hello, SkyDance, you wrote: SD> Not sleep (), and wait (). Read about synchronization. If it is necessary to supervise accurately, yes, wait (). But so they equally work. Both and that the flow stops that.

31

Re: How to write the code consuming about 10 % of the processor?

Hello, SkyDance, you wrote: SD> Or you want other? Then formulate the task was more specific. Here I open mspaint. It, according to the manager of tasks,  1.5 % of the processor. I want to understand, how it is made.

32

Re: How to write the code consuming about 10 % of the processor?

Hello, Terix, you wrote: T> Hello, SkyDance, you wrote: SD>> Or you want other? Then formulate the task was more specific. T> here I open mspaint. It, according to the manager of tasks,  1.5 % of the processor. I want to understand, how it is made. It is interesting to you as the manager of tasks does it https://technet.microsoft.com/en-us/lib … 34903.aspx https://software.intel.com/en-us/articl … er-monitor https://github.com/opcm/pcm or how mspaint 1.5 % manage to gobble up?

33

Re: How to write the code consuming about 10 % of the processor?

Hello, kov_serg, you wrote: _> or how mspaint 1.5 % manage to gobble up? Here too it is interesting to me.

34

Re: How to write the code consuming about 10 % of the processor?

Hello, Terix, you wrote: T> Meanwhile the cleverest that I invented - to do sleep. But it can is possible somehow on another? "10 % of loading of the processor" means that the scheduler of OS selects to this process of 10 % from the general processor capacity. When the flow receives quantum of time from the scheduler, there are two methods to complete this quantum and to ship a flow reversely in a sleeping mode: the scheduler can interrupt flow performance (it and is called a preemptive multitasking), or the flow can give control voluntary. In Java it is called thread park and is controlled or from within a flow through synchronization functions, or outside through LockSupport. Try to fulfill calculations in one flow, and to "quantize" hands from other flow, causing park on 90 from 100 for example. Instead of Sleep it is better to use Condition.awaitNanos. Still a variant - to write the code so that it was executed exactly 10 and to cause it through ScheduledExecutorService time in 100.

35

Re: How to write the code consuming about 10 % of the processor?

To me here it was thought, if you so want to do through sleep () it is possible to implement about such algorithm: we calculate 10 frames for display and time, for how many the display flow deduces a part that remains only 5, we do sleep () for this time. When we wake up - it is calculated frames that them again in queue became 10, again we time, how many it is necessary to have a sleep, that there were 5 frames - is done sleep (). Here it is necessary to consider that loading on the machine, therefore in due course can change both time of calculation of a frame and time of its display can change, therefore these times are useful for enumerating on each iteration. It is possible to take other numbers, not 10 and 5, but it is necessary to consider that sleep () will be not exact and under loading after sleep () the flow can long wake up and more slowly generate new frames, the store therefore is necessary. It is possible to do calculation and display and in one flow, but here it is necessary to calculate before  what to do then - to display the next frame or to generate, on it will depend how many to sleep prior to the beginning of display of a following frame or prior to the beginning of generation of a new pack (I would do it in different flows).

36

Re: How to write the code consuming about 10 % of the processor?

T> Here I open mspaint. It, according to the manager of tasks,  1.5 % of the processor. I want to understand, how it is made. Open the book of Russinovicha, and there it is a lot of on this subject. If it is short - yes in any way, this number does not mean anything in your case.

37

Re: How to write the code consuming about 10 % of the processor?

Hello, SkyDance, you wrote: SD> Open the book of Russinovicha, and there it is a lot of on this subject. SD> if it is short - yes in any way, this number does not mean anything in your case. Well at least fans on the processor do not turn on and so on. For me a unique method to write the code by which the such does - to use existing  type QT. As such to make using  in a cycle by means of OpenGL I do not know. You want to tell, what it  is impossible?

38

Re: How to write the code consuming about 10 % of the processor?

T> Well at least fans on the processor do not turn on and so on. For me a unique method to write the code by which the such does - to use existing  type QT. As such to make using  in a cycle by means of OpenGL I do not know. You want to tell, what it  is impossible? You seriously do not know, what such event loop (an operation cycle of events) in graphic applications?

39

Re: How to write the code consuming about 10 % of the processor?

T> Well at least fans on the processor do not turn on and so on. Fans turn on not on informed task manager' .

40

Re: How to write the code consuming about 10 % of the processor?

Hello, Masterspline, you wrote: M> You seriously do not know, what such event loop (an operation cycle of events) in graphic applications? Somewhere in a graphic application there is a cycle in which each iteration events of type of relocation of the mouse, pushing of keys and all such are pulled out and processed. Plus is processed any logic. If the logic fulfills long events collects more, if quickly it is less. In if  logicians transits quickly it it will be simple to be caused more often and all the same  the processor on the full. At least so at me it turns out with SDL. In graphic applications all evidently not so but as it is implemented, I not in course.

41

Re: How to write the code consuming about 10 % of the processor?

Hello, Terix, you wrote: T> Generally imagine that we have a cycle shorthanding to the physicist. It also shorthands the world of 400 times in a second. Also loads percents on 100 % and for simulation to us and 40 times a second suffices. If simply to pass cycles entrance in while all the same  system on 100 %, and it not that that is necessary for us. Would Remain sleep like. And why it shorthands not on demand? Looks like a-lja Sync to V-Blank. Here it is necessary not sleep, and a method of synchronization which allows to clear a flow when it is necessary, instead of when any time transits (condvar, message queue, etc.).

42

Re: How to write the code consuming about 10 % of the processor?

In event loop can quite come not only type events "the mouse was moved" or "here this window needs to be drawn again, because its sizes changed", but also events from the timer. I.e. you can make, for example, so. After start of application and creation of an initial picture you calculate one frame,  it, you generate in queue one more frame and you cock the timer that you woke when it will be necessary to display a frame from queue, you fall asleep. When you wake - you draw a frame from queue and you generate following, you put the calculated frame in queue, you cock the timer, when you to wake to display the next frame. . And so on a circle (but here it is necessary to consider that can wake you hardly later, at calculation of the next frame the machine can be loaded by other tasks, therefore time of calculation of a frame will change in due course, therefore it is useful to calculate in advance more than one frame, still it is necessary to display a new frame that the picture for the user did not twitch at loading change on the machine with stable intervals, therefore it is necessary to make so that during the moment when it is necessary to display the next frame, the flow was not engaged in following calculation)... In that case at you frames are displayed with the interval predetermined by you and when the next frame is calculated and it is necessary to wait for time  - application sleeps.