Skip to Main Content

Infrastructure Software

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Interested in getting your voice heard by members of the Developer Marketing team at Oracle? Check out this post for AppDev or this post for AI focus group information.

What is Multi Threading

JimboJan 9 2015 — edited Jan 16 2015

Hi, I am trying to get my head round Multi Threading and I have a few queries to try and clear up my confusion

    

Q1. Is multi threading a hardware / chip level concept, an OS level or an application / code level concept ? I am trying to work out where SMT
architecture fits in.

Q2. What’s the multi threading position in relation to Unix, Linux and Windows ?

Q3. Is multi threading only in relation to application processes or is it for OS processes as well ? I am trying to differentiate multi threading from the older CPU concepts of timeslicing, round robin etc

    

My understanding is that you can have multi processing systems which switch between or execute processes in parallel. However multi
threading takes this a step further in that a process can be broken down into threads and the processor execute the individual threads ( again via switching or parallel depending on the number of processors / cores you have )

    

Q4. Are processors therefore specifically designed either to execute full processes, threads or both ? Can a single processor execute a mix
of full processes and threads ? i.e. does a processor operate only at either a process level or a thread level ?

Q5. What’s the difference between a single processor with multi cores and a mult processor with single core processors ?

    

Q6. Are most modern processors today, multi thread capable processors ( or is it the OS which determines this ). Does the processor have to be specifically set to multi thread ?

Any wisdom greatly appreciated,

thanks Jim

Comments

Dude!

A1) Multithreading employs the concept of parallel process execution. You can find in hardware and software. SMT is about hardware multithreading.

A2) Multithreading concepts are used on all modern computer platforms.

A3) Multitasking is about processes sharing common resources, such as a CPU. The most common is preemptive multitasking, where the OS decides how much CPU time gets allocated to individual processes. Multithreading extends the idea of multitasking into applications, OS and hardware. Multitasking allows a process to subdivide specific operations into individual sub-processes or threads that can run in parallel.

A4) Multitasking and multithreading are concepts that can run on a single CPU. However, a process can only run on a specific CPU at a time. A single process can not execute on multiple CPU's. In order to take advantage of multiple CPU's, multiple processes or threaded operations are required.

A5) The difference between, e.g. dual CPU and dual core is hardware. Dual core, for example, means 2 CPU's in one physical CPU unit, whereas dual CPU's mean duplicate hardware, such as CPU sockets and CPU bus. Multi-core architecture is cheaper because it requires less hardware and less power, and has other advantages in terms of resource sharing, but also has it's disadvantages, like less hardware redundancy, for example.

A6) Multithreading is not a feature or concept that only applies to CPU architecture, but also software. Multithreading can be used on a single CPU as well as separating processes among multiple CPU's.

Jimbo

Thanks.

Q1. So will modern processors automatically multithread processes or do you have to specifically set or configure the processor to do this ?

Q2. I presume if your multi threading is at the hardware level this is really a combination of the processor / OS i.e. it is not transparent to the OS ? Therefore is Unix, Linux and Windows OS's that natively use multi threading ( or do you have to specifically enable it, depending on whether the underlying processor can support multi threading ) ?

Q3. So is there a difference between OS level multi threading and application /coding level multi threading ?

Q4. Are OS level and Application / Code level multi threading independent of each other ? i.e. if you are going to use Application / Code level multi threading must you have a processor / OS that is capable of multi threading ? Is it possible to have multi threading at your application / coding level on a system that has a processor that itself does not multi thread - if so how is this different from the concept of parallel processing on any multi user / process system ?

Q5. Does your code / application have to use specific libraries / procedures etc in order to multi thread i.e. is it a specific type of coding that facilitates application / code level multi threading ?

thanks,

Jim

Dude!

I'm afraid your questions are too complex to be answered individually. As far as I understand, processes are a logical software construct that have no meaning for the CPU as such. On the CPU level, multithreading is typically achieved by multiplexing and context switching, which gives only the impression of running parallel tasks. However, I'm not a CPU designer and I suggest to look for information on the web.

Multithreading implemented by the OS or application does not necessarily depend on the CPU or number of CPU's like I previously mentioned, except that the system needs to be powerful enough to be able to handle parallel tasks. Hardware can provide support that can be beneficial for threaded tasks and may require appropriate software and drivers. Perhaps synchronous vs. asynchronous non-blocking I/O would be a good example.

To implement multithreading, the application and OS must support the concept of running parallel tasks and provide the appropriate code. For example, to copy one file at the time or be able to submit several parallel file copy tasks at once. In all cases, the application and OS need to be able to compute and manage the individual tasks or processes, manage file system integrity and to recover and provide information about errors.

From the perspective of an application programmer, multithreading is a concept that requires appropriate software or programming library support. Some of libraries are cross-platform. http://www.gnu.org/software/pth/related.html

Btw, do you need this information for something specific or is this just general interest?

Jimbo

Thanks Dude,

I was really trying to discern if both Unix and Windows as OS's were multi thread capable, out of the box or if there is something special you have to set up to make them multi thread

It then struck me that I didn't quite understand multi threading as well as I thought I did !

I was confused because there seemed to be different references about multi threading by a processor, multi processing by the OS and multi threading by code / applications and the 3 seemed to be presented as different concepts. I am still not sure if the processor and OS level multi threading is effectively the same concept ?

I was also confused about what the difference was between multi threading at the processor level and the old CPU concepts I learned about multi tasking i.e. round robin time slicing etc ?

thanks,

Jim

Dude!

Multi-processing and multi-threading is all about parallel processing. Multi-processing or multi-threading does however not mean you need multiple processors or CPU's. You can also do multi-processing or threading on a single CPU or single-core, in which case the CPU is switching between the processes or threads in a timely fashion to make it seem like parallel processing. This is called Context Switching and most modern system use a CPU scheduling in a round-robin fashion.

Multi-process means separate processes in the system process table. Multi-threaded means threads associated with a process, which share the same address space. To see threads in Unix or Linux, you can use the "ps" command with the "-L" option.

There is nothing you have to do to make Windows or Linux multithreading. Every modern OS provides the necessary support. Whether an application is multi-threaded, depends on the application.  Oracle database introduced a new multi-process multi-threaded architecture for Unix and Linux in 12c. https://docs.oracle.com/database/121/CNCPT/process.htm#CNCPT1245.


In some tests, memory usage was almost divided by half when using multi-process multi- threaded feature. The default in Oracle 12c is not multi-threaded, but you can enable it:

SQL> ALTER SYSTEM SET threaded_execution=true SCOPE=SPFILE;


Perhaps what you might also want to keep in mind is that a single process or single thread can only run on a single CPU or core at a time. Or said differently, a single process or single thread cannot take advantage of mulitple CPU's or multi-core architecture.

Jimbo

Thanks Dude that is all very interesting.

I guess I need to know more about the evolution of CPUs. Multi Processing has been around for as long as there have been multi user based operating systems - right back to the days of main frame technology. This is why I was aware of the concepts of round robin time slicing etc - I presume Context Switch refers to how the CPUs dealt with multi processing and Multi Threading as opposed to just how it deals with threads ?

So I guess the old multiprocessing CPU scheduling systems such as Round Robin are also referred to as Context Switching ?

I guess some where along the line, the various processors introduced the concept of Multi Threading - I know Intel introduced it as SMT back in 2002 for their Pentium 4 processor, I am not sure if the big RISC based processors from the likes of Sun, IBM, HP etc introduced it before or after Intel ?

I am also not sure if the arrival of multi threading was firstly just for OS processes and then alter it was expanded to allow end user applications / code to multi thread or if end user applications were able to avail of it from day 1 of its introduction - again more history !

Oracle is also an interesting story - prior to 12c I knew their RDBMS software did not make use of any underlying multi threading capability of the host OS, instead they had their own sort of deployment of multi threading through their Multi Threaded Server ( MTS ) deployed via their Oracle Net layer, where basically a Dispatcher process allowed multiple end user processes to share a single backend database server process. However from 12c as you point out, the RDBMS can now make use of any native OS level multi threading. I must check if this means that MTS is dead from 12c onwards or if it still could be used ( for whatever obscure reason )

thanks,

Jim


Dude!

I would not necessariliy draw a direct connection between multi-threading, multi-processing, multi-user, multi-core and the way how CPU's work. There is a lot of "multi" and some of the features benefit from each other, but the concepts do not depend on each other and were based on individual development and what was techncially feasible or requried at a certain time.

1 - 7
Locked Post
New comments cannot be posted to this locked post.

Post Details

Locked on Feb 13 2015
Added on Jan 9 2015
7 comments
2,326 views