How do threads get handled? [closed] - c++

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 9 years ago.
Improve this question
Am I getting it right, that if you have for example four CPU's and four threads, these are getting distributed on each CPU? And when you have got five threads, one CPU has to handle two threads at once?
Thanks in advance :)

The only guarantee you get is that the threads will run independently of each other. Scheduling is done by the operating system and the OS usually tries to make all cores busy, but since there is a lot more running on your computer than just your program, there's no guarantee that your four threads will always run on the four cores.
On Windows, you can pin threads to a processor core, but this is neither standard nor cross-platform, and not always to the benefit of your program.

Related

How to cross thread calls in native C++ (call back on main thread) [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 4 years ago.
Improve this question
I am implementing the C++ mobile apps to call some process which taking some times to make it done, but I need my apps main thread is still running without any blocking.
Question:
Is there any library that could just call runOnUIThread to get back the result on main thread?
Understand that there a lot of answer such as message event queue polling to get back the result on main thread, or using future/promise to keep looping the result. But I don't want these kind of solution to achieve the target.
I believe in C++ way has some function to get back main thread looper and call the function with multiple entry point to main thread? I have red this article, I'm not really understand what it means, hope someone could help.
Cross Thread Call in native C++
C++ as a language does not have a standard way of doing cross thread messaging. This means you need to implement your own solution that depends on the frameworks you are using.

Number of processors / Number of cores per processor Intel Core 2 Duo [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 7 years ago.
Improve this question
I'm confused about years, what is the correct setting for this processor Intel Core 2 Duo, here is the specification.
I can set Number of processors to 2 and Number of cores to 1 or
I can set Number of processors to 1 and Number of cores to 2 and both setting works.
From my point of view the second option is right, because I have physically only one processor on the motherboard.
Thank you for confirmation and comments.
You must consider always the processor as the physical unit. So, Core2Duo is a SIngle Processor with 2 cores.
For instance, the i7-4970 is a Single CPU with 4 cores in Hyperthreading (you may consider like 8 cores).

C++ code - Coverity (or some other static code analyzer) + thread safety [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 7 years ago.
Improve this question
I was wondering today about the following: is there any tool or extension (for coverity or for other code analyzer), where I can do the following?:
First, I would set a set of rules, that which codes are generating new threads, so the analyzer knows, that the code will run other thread.
The tool must follow, which code parts are in which threads, are they in the same, or in different ones.
I could set "rules", what kind of codes are ensuring me thread safety: for example a MYLOCK class is locking between threads.
And the reason for the previous 3: the tool should show me warnings, which codes are most likely called by different threads and doesn't have thread-safety usage in it.
Thanks
Try Intel Inspector (also known as Thread Checker). It is dynamic analysis, not static. As far as I remember, it allowed some annotation/instrumentation for custom locks, threading libs in general.

Is there any way to allow multithreading on a program with a loop like this one? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
Is there any way to allow multithreading on a program with a loop like this one?
int a=100000,b=50,c;while(a){c=b*a+c;a--;}
Windows 7/Code::Blocks IDE with the default mingw c++ compiler/Dual-core 4 threaded i5 cpu
This isn't a programming issue per se.
Your CPU has either four cores, or two cores with hyperthreading. The program is using 100% of 1 core, which is reported as 25% usage in the Windows task manager.
You won't be able to 'increase your CPU usage' without threading.
(As an aside, the reason you see it as 'distributed between the four threads' is because the operating system is, if you like, changing its mind about which core it wants to run your program on. Such issues of scheduling can't be changed (and won't have a noticable impact on) individual programs.)

Considering the Chaos Monkey in Designing and Architecting an Embedded Systems [closed]

Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 10 years ago.
Improve this question
I work on embedded systems with limited memory and throughput. Making a system more robust requires more memory, and time on the processor. I like the idea of the Chaos Monkey to figure out if your system is fault tolerant, however with limited resources I'm not sure how feasible it is to just keep adding code to it. Are there certain design considerations whether in the architecture or otherwise that would improve the fault handling capabilities, without necessarily adding "more code" to a system?
One way I have seen to help in preventing writing an if then statement in c (or c++) that assigns rather then compares a static value, recommends writing that on the left hand side of the comparison, this way if you try to assign your variable to say the number 5, things will complain and you're likely to find any issues right away.
Are there Architectural or Design decisions that can be made early on that prevent possible redundancy/reliability issues in a similar way?
Yes many other techniques can be used. You'd do well to purchase and read "Code Complete".
Code Complete on Amazon