04 01 Threads and Concurrency Part 1a — Transcript
Full transcript
- 0:01[Music]
- 0:08[Music]
- 0:20hello there
- 0:22this video lecture covers
- 0:25threads
- 0:26and concurrency
- 0:28okay so this topic is next to processes
- 0:32okay so the last video that we had
- 0:35all right
- 0:36so let's get started
- 0:38so bear with me this discussion is a
- 0:40little bit too technical okay and we
- 0:43will be dealing with a lot of terms here
- 0:46okay so for the outline of the video so
- 0:50we will be dealing with an overview
- 0:52of a thread okay
- 0:55so also included are the multi-core
- 0:58programming
- 0:59the multi-threading models the thread
- 1:02libraries
- 1:03implicit threading
- 1:05the threading issues and some operating
- 1:08system examples when it comes to threads
- 1:12okay so at the end of this discussion so
- 1:16we should be able to identify the basic
- 1:17components of a thread
- 1:20and contrast threads and processes so
- 1:24last time we we talked about process and
- 1:27when she processed this is a programming
- 1:29execution okay so how about threads so
- 1:32threads
- 1:33before okay
- 1:35during the process discussion we defined
- 1:37it as
- 1:38a sub process
- 1:40all right
- 1:42next would be
- 1:43describe the benefits and challenges of
- 1:46designing a multi-threaded applications
- 1:49illustrate different approaches to
- 1:52implicit trading including tread pools
- 1:55fork join
- 1:56and grand central dispatch
- 2:00so describe how windows and linux
- 2:02operating systems
- 2:04represent threads
- 2:05and design a multi-threaded application
- 2:08using the pthreads java and the windows
- 2:12trading apis
- 2:24[Music]
- 2:32so let's start with the definition of
- 2:35thread so what is the thread okay
- 2:37so thread basically is a basic unit of
- 2:40cpu utilization
- 2:42consisting of a program counter
- 2:45a stack
- 2:46and a set of registers
- 2:49and a thread id
- 2:51okay
- 2:52so what what are the motivations for
- 2:54having a thread
- 2:56okay so most modern applications are
- 2:59multi-threaded
- 3:01okay so threads run within application
- 3:05so that means
- 3:07thread is
- 3:09a sub process
- 3:11okay so multiple tasks
- 3:13with the application can be implemented
- 3:15by separate threads so update display
- 3:20fetch data spell checking so our example
- 3:23is of course in microsoft word okay so
- 3:26we're in when we run the application we
- 3:28have a lot of threads okay so that was
- 3:31initialized when we open it
- 3:34okay and then answer a network request
- 3:37is also
- 3:38a good example
- 3:40okay so process creation is a heavy
- 3:44weight
- 3:45while trend creation is a light rate so
- 3:47that's why we have the motivation for
- 3:50creating a thread okay so it can simply
- 3:53simplify the code and increase
- 3:55efficiency
- 3:57kernels are generally multi-threaded
- 4:00okay
- 4:01so basically threads are very useful in
- 4:04modern programming
- 4:05so whenever a process has multiple tasks
- 4:08to perform independently
- 4:10of the others
- 4:11okay so a good uh multi-threaded
- 4:15application for programming is of course
- 4:17java
- 4:18okay
- 4:19so this is particularly true when one of
- 4:22the tasks may block
- 4:25and it is desired to allow the other
- 4:27tasks to proceed without blocking so for
- 4:30example
- 4:32so in a word processor
- 4:34a background thread may check spelling
- 4:36and grammar
- 4:38while a foreground thread
- 4:40process or processes user inputs like
- 4:42keystrokes
- 4:44okay
- 4:45so while yet a third thread loads images
- 4:49from the hard drive and the fourth does
- 4:51periodic automatic backups
- 4:54of the file being edited okay
- 4:56so let me open here
- 5:00a
- 5:01[Music]
- 5:03task manager so that we'll be able to
- 5:05see the threads there okay
- 5:19all right
- 5:20so we have here our task manager okay so
- 5:24of course we have here the process is
- 5:26running
- 5:27okay
- 5:28and basically you'll have the background
- 5:30processes and
- 5:32some foreground processes running here
- 5:34okay or the windows processes
- 5:37now so these are the resources allocated
- 5:40to each of the process
- 5:41okay
- 5:42now looking at the performance so let's
- 5:45examine the cpu utilization here so the
- 5:48cpu utilization is 36 percent so i'm
- 5:51using 2.7
- 5:54okay plus plus gigahertz
- 5:56of the cpu frequency here
- 5:59okay
- 6:00now
- 6:01if you will observe here with a 38
- 6:04utilization okay and the speed of 2.74
- 6:07though the cpu is basically 2.3
- 6:09gigahertz so you'll you'll have that um
- 6:12it exceeded the the frequency okay now
- 6:15what i want you to pay attention here is
- 6:18the number of processes here okay
- 6:21now for the number of processes so
- 6:23currently we are running 155 processes
- 6:27and there are about
- 6:291683 threads
- 6:31okay so if you are running virtual
- 6:33machines like virtualbox so you would
- 6:35also see here if you have enabled the
- 6:38virtualization on the
- 6:41cmos
- 6:42all right
- 6:43now
- 6:44so currently i'm running 153 processors
- 6:47and with that processes there are about
- 6:49a thousand six hundred plus threads okay
- 6:53so let me open ms word here okay
- 6:57so windward
- 7:01let me open it and what i want you to
- 7:03pay attention with is the number of
- 7:05threads there okay
- 7:06so
- 7:08examine or observe what will happen
- 7:10when i open ms word
- 7:15all right so there is a sudden increase
- 7:18of the number of threads
- 7:20okay
- 7:21so we just opened microsoft word there
- 7:23all right
- 7:24and microsoft word has a lot of threads
- 7:26associated with it so as mentioned
- 7:28earlier so this includes like spelling
- 7:31check
- 7:32okay
- 7:33uh grammar check
- 7:35what else uh the keystrokes the number
- 7:37of characters and so on
- 7:39okay
- 7:41so let me close this
- 7:44all right so
- 7:46next
- 7:52okay so we have
- 7:54what we call a single threaded or a
- 7:56multi-threaded processes
- 7:59so traditionally
- 8:01we've got the heavyweight processes
- 8:03it has a single thread of control so
- 8:06there is one program counter
- 8:08and a sequence or one sequence of
- 8:10instructions that can carry it out at
- 8:13any given time
- 8:15okay now as shown in this diagram here
- 8:18okay so we've got a multi-threaded
- 8:21applications
- 8:22okay and it has multiple threads with a
- 8:25single process
- 8:27okay
- 8:28so you've got multiple threads here okay
- 8:30so this string
- 8:32like
- 8:34diagram or symbol here represents a
- 8:36thread okay
- 8:38now we have here
- 8:40a multi-threaded process if you will
- 8:42observe we have three
- 8:43threads running with a single process
- 8:46and each of the thread has their own
- 8:48registers stack and program counter
- 8:51but the code the data and the files are
- 8:54shared among the threads
- 8:57all right
- 9:03all right
- 9:04so next would be the multi-threaded
- 9:06server architecture okay so what do we
- 9:09have in the multi-threaded architecture
- 9:12so another example of
- 9:14a thread okay so like what we've
- 9:16mentioned earlier ms word example so
- 9:19another example is the web server
- 9:21so multiple threads allows or allow for
- 9:24multiple requests to be satisfied
- 9:26simultaneously okay without having to
- 9:29service the request sequentially
- 9:31or to fork
- 9:33separate processes for every incoming
- 9:35request
- 9:36okay
- 9:37so a dame one would listen at a port
- 9:41fork of a child for every incoming
- 9:43request
- 9:44to process
- 9:46and then
- 9:47go back to the listening port
- 9:50all right
- 9:51so
- 9:52that is shown on this diagram here
- 9:56okay
- 9:57so next would be
- 10:00what are the benefits of a trend
- 10:03okay so basically there are four major
- 10:05categories of benefits
- 10:07to multi-threading so these are
- 10:09responsiveness
- 10:10resource sharing economy and scalability
- 10:14okay
- 10:15now on the responsiveness so one thread
- 10:18may provide rapid response while other
- 10:21threads are blocked or slowed down doing
- 10:24intensive calculations
- 10:27all right
- 10:28so next would be resource sharing
- 10:31so by default
- 10:32threads share common code data and other
- 10:35resources as shown in the model earlier
- 10:37okay so which allows multiple tasks
- 10:41to be performed simultaneously in a
- 10:43single address space
- 10:45that's resource sharing
- 10:47okay
- 10:49third is economy
- 10:51so creating and managing threads and
- 10:53contact switches between them
- 10:55is much faster than performing
- 10:58same tasks for processes
- 11:01all right so that's economy
- 11:03and the last one would be scalability so
- 11:05an example of this is the utilization of
- 11:08a multi-processor architectures
- 11:10okay so a single threaded process can
- 11:12only run one or can only run on one cpu
- 11:16no matter how many
- 11:18may be available
- 11:20whereas the execution of a
- 11:21multi-threaded application
- 11:23may be split amongst available
- 11:25processors
- 11:27okay so note that a single threaded
- 11:29process can still benefit from a
- 11:31multi-processor architectures
- 11:34when there are multiple processes
- 11:36contending for the cpu
- 11:38example when the load average is above
- 11:41some certain threshold
- 11:43okay so
- 11:45basically the use of threads are
- 11:47beneficial
- 11:49all right
- 11:54[Music]
- 12:06you
About this transcript
This page contains the full transcript of 04 01 Threads and Concurrency Part 1a by Santelmo, generated from the public captions YouTube serves with the video. The transcript has 1,336 words across 291 segments, with the original timestamps preserved so you can click any line to jump to that moment in the embedded player.
What you can do with it
Use the transcript to take notes, quote the speaker, build a study guide, generate a summary with ChatGPT or Claude via the YouTube Summary tool, or export it as a timed subtitle file with YouTube to SRT. You can also re-open it in the transcriber to translate the transcript into 100+ languages.
Free YouTube transcript tool
YouTube2Text is a free YouTube transcript generator — no signup, no daily limit. Paste any YouTube link and get the full transcript instantly, with timestamps, click-to-jump, translation to 100+ languages, AI prompts for ChatGPT, Claude, and Gemini, and exports to TXT, SRT, VTT, or Markdown.