-2

Today I was trying to understand what multithreading and hyperthreading are. However I have several doubts regarding it.

  1. In multithreading, what happens when two threads try to modify the same location simultaneously?

  2. Are threads completely operating system concepts and CPU have no idea about them? It sees them as processes?

hyperthreading allows an operating system to see double the amount of logical cores per physical core.

  1. Does that mean every physical core executes two process simultaneously? Or it means Two threads simultaneously?

So basically I am confused between processes and threads in case of hyperthreading. Also What happens when dependent threads and processes arrive in case of multithreading and hyperthreading?

closed as too broad by random Aug 28 '15 at 19:32

Please edit the question to limit it to a specific problem with enough detail to identify an adequate answer. Avoid asking multiple distinct questions at once. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

  • 1) This cannot happen; 2) No; Threads are not a concept limted to just the OS; 3) Hyperthreading means that a single core can process 2 threads, this is different from a CPU which has multiple cores for obvious reasons. – Ramhound Aug 28 '15 at 18:51
3
  1. Simultaneous access: This is an extremely complex question. At a very low level, of accessing individual memory locations, the hardware takes care of it by possibly blocking one thread for a few clock cycles. At a higher level— what a programmer usually deals with— you are normally expected to use locks, semaphores, message queues, transactional memory, or some other mechanism to keep it from happening; or to use carefully-designed "lock-free" algorithms along with atomic primitives. Getting this right is difficult.
  2. More or less. Threads can also be thought of as processes which share their virtual address space. Threads are sometimes called "lightweight processes" for this reason. Of course, it is equally valid to think of processes as threads which have different address spaces (and other kernel resources).
  3. Hyperthreading: Modern CPUs are so much faster than memory (even cache memory) that they spend most of their time waiting rather than actually processing. Superscalar processors can execute multiple instructions at a time but most code has too much self-dependency to really take advantage of this. Hyperthreading allows two threads to be scheduled to use the same core's resources so that, hopefully, the resources can be fully utilized. Sometimes it works out better than just using two cores, sometimes not.
  • Additíonally: Programming multiprocessing/threaded applications needs the same type of attention as programming RTOS (real time OS) applications. There is no CPU magic in it, just workmanship and knowledge. – Hannu Aug 28 '15 at 20:06

Not the answer you're looking for? Browse other questions tagged or ask your own question.