Click here to Skip to main content
15,867,288 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
I have one core in my computer.

Can i use threads to execute 2 different codes separately simultaneously at any given moment to improve performance?

Or one core has only one execution pipeline?

In other words, is it possible to execute a few codes simultaneously at any given moment on one core using threads or timers?
Posted
Comments
Sergey Alexandrovich Kryukov 28-Dec-14 11:44am    
It all depends on what do you mean by "simultaneous". Nothing is "simultaneous". Multithreading for one core worked for decades. Why not, after all? Do you have a clue how threading works?
—SA

Generally you can create as many threads as you need and the OS/Cpu will manage the scheduling and execution.

Try and see is the general answer since we have no clue as what your app is and how it is written.
 
Share this answer
 
Comments
Ziya1995 28-Dec-14 8:56am    
One core, 2 threads:
1. They run simultaneously at any given moment.
2. They run step by step by queue and wait while another thread runs and it is like "simultaneously ", but in actually it is not.
What is right?

Your answer is not solution, sorry.
Quote:
I'm not an expert on multiprocessing in Intel systems, but I think the best way to look at it is that one core cannot execute two instructions at the same time. That may not be technically correct as the hardware may split an instruction into separate parts and execute different parts at the same time.

My understanding is that if you run two threads on one core, there will be some overhead associated with switching between the threads which will tend to make the whole process slower. So if you have a job that is all calculation (like calculating Pi to a large number of decimal places), you will finish the fastest if you have one active thread per core. However, if the job you are doing has pauses where no instructions are being executed (for example if it is waiting for input, or for data that is being read), then the operating system may be able to fill those pauses in one thread with useful work from another thread. That will speed up your job if the time recovered is enough to make up for the overhead of switching threads.

For example, if you run your job in a single thread on a single core and Task Manager shows the CPU as 75% busy, then the best you could hope for by using multiple threads is to make the CPU 100% busy (about a 33% improvement).


https://social.msdn.microsoft.com/Forums/en-US/858674a9-0ede-481e-bd80-2d4c8f8c7787/timer-vs-thread-is-there-a-difference-in-execution[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900