Без темы
<<  Private Banking Customized Financial Planning PROJECT ACHIEVEMENTS: UKRAINIAN EXPERIENCE – LESSONS LEARNED  >>
(UNIX) FORK-JOIN construct
(UNIX) FORK-JOIN construct
Differences between a process and threads
Differences between a process and threads
Pthreads IEEE Portable Operating System Interface, POSIX standard
Pthreads IEEE Portable Operating System Interface, POSIX standard
Pthreads Detached Threads
Pthreads Detached Threads
3. Accessing Shared Data Accessing shared data needs careful control
3. Accessing Shared Data Accessing shared data needs careful control
Control of critical sections through busy waiting
Control of critical sections through busy waiting
Pthread Condition Variables Pthreads arrangement for signal and wait:
Pthread Condition Variables Pthreads arrangement for signal and wait:
Illustration
Illustration
Deadlock Can occur with two processes when one requires a resource
Deadlock Can occur with two processes when one requires a resource
Deadlock Deadlock can also occur in a circular fashion with several
Deadlock Deadlock can also occur in a circular fashion with several
Pthreads program example
Pthreads program example
37
37
38
38
Картинки из презентации «Programming with Shared Memory Threads Accessing shared data Critical sections» к уроку английского языка на тему «Без темы»

Автор: Barry Wilkinson. Чтобы познакомиться с картинкой полного размера, нажмите на её эскиз. Чтобы можно было использовать все картинки для урока английского языка, скачайте бесплатно презентацию «Programming with Shared Memory Threads Accessing shared data Critical sections.ppt» со всеми картинками в zip-архиве размером 333 КБ.

Programming with Shared Memory Threads Accessing shared data Critical sections

содержание презентации «Programming with Shared Memory Threads Accessing shared data Critical sections.ppt»
Сл Текст Сл Текст
1Programming with Shared Memory Threads 19exclusion. Concept also appears in an
Accessing shared data Critical sections. operating systems. 19.
8a-1. ITCS4145/5145, Parallel Programming 20Locks Simplest mechanism for ensuring
B. Wilkinson Jan 4, 2013 slides8a.ppt. mutual exclusion of critical sections. A
2Shared memory multiprocessor system. lock - a 1-bit variable that is a 1 to
Processors cores and processors. Single indicate that a process has entered the
address space exists – each memory critical section and a 0 to indicate that
location given unique address within no process is in the critical section.
single range of addresses. Any memory Operates much like that of a door lock: A
location can be accessible by any of the process coming to the “door” of a critical
processors. Multicore processors are of section and finding it open may enter the
this type. Also multiprocessor servers critical section, locking the door behind
such as coit-grid05.uncc.edu, which have it to prevent other processes from
both multicore processors and multiple entering. Once the process has finished
such processors. Address 0 1 2 3. Memory the critical section, it unlocks the door
locations. 2. and leaves. 20.
3Programming a Shared Memory System 21Control of critical sections through
Generally, more convenient and efficient busy waiting. 21.
than message passing. Can take advantage 22Pthreads Lock routines Locks
of shared memory for holding data rather implemented in Pthreads with mutually
than explicit message passing to share exclusive lock variables, or “mutex”
data. However access to shared data by variables: …
different processors needs to be carefully pthread_mutex_lock(&mutex1); critical
controlled usually explicitly by section pthread_mutex_unlock(&mutex1);
programmer. Shared memory systems have … If a thread reaches mutex lock and finds
been around for a long time but with the it locked, it will wait for lock to open.
advent of multi-core systems, it has If more than one thread waiting for lock
become very important to able to program to open, when it does open, system selects
for them. 3. one thread to be allowed to proceed. Only
4Methods for Programming Shared Memory thread that locks a mutex can unlock it.
Multiprocessors Using heavyweight Same mutex variable. 22.
processes. Using threads explicitly - e.g. 23Condition Variables Often, a critical
Pthreads, Java threads Using a sequential section is to be executed if a specific
programming language such as C global condition exists; for example, if a
supplemented with compiler directives and certain value of a variable has been
libraries for specifying parallelism. e.g. reached. With locks, the global variable
OpenMP. Underlying mechanism on OpenMP is would need to be examined at frequent
thread-based. Using a “parallel intervals (“polled”) within a critical
programming” language, e.g. Ada, UPC - not section. Very time-consuming and
popular. We will look mostly at thread unproductive exercise. Can be overcome by
API’s and OpenMP. 4. introducing so-called condition variables.
5Using Heavyweight Processes Operating 23.
systems often based upon notion of a 24Pthread Condition Variables Pthreads
process. Processor time shares between arrangement for signal and wait: Notes:
processes, switching from one process to Signals not remembered - threads must
another. Might occur at regular intervals already be waiting for a signal to receive
or when an active process becomes delayed. it. Pthread_cond_wait() unlocks mutex1 so
Offers opportunity to de-schedule that it can be used other thread and
processes blocked from proceeding for some relocks it after woken up. Value of c
reason, e.g. waiting for an I/O operation checked in both threads. 24.
to complete. Concept could be used for 25Critical Sections Serializing Code
parallel programming. Not much used High performance programs should have as
because of overhead but fork/join concepts few as possible critical sections as their
used elsewhere. 5. use can serialize the code. Suppose, all
6(UNIX) FORK-JOIN construct. Fork here processes happen to come to their critical
creates a complete copy of the main section together. They will execute their
program and starts it at the same place as critical sections one after the other. In
the Fork. Both programs continue together. that situation, the execution time becomes
6. almost that of a single processor. 25.
7UNIX System Calls. No join routine – 26Illustration. 26.
use exit() to exit from process and wait() 27Deadlock Can occur with two processes
to wait for slave to complete: … pid = when one requires a resource held by the
fork(); if (pid == 0) { // code to be other, and this process requires a
executed by child } else { //code to be resource held by the first process. 27.
executed by parent } if (pid == 0) 28Deadlock Deadlock can also occur in a
exit(0); else wait (0); … 8a-7. circular fashion with several processes
8Differences between a process and having a resource wanted by another. 28.
threads. 8. 29Pthreads pthtrylock routine Offers one
9Pthreads IEEE Portable Operating routine that can test whether a lock is
System Interface, POSIX standard. 9. actually closed without blocking the
10Detached Threads It may be that thread thread: pthread_mutex_trylock() Will lock
are not bothered when a thread it creates an unlocked mutex and return 0 or will
terminates and then a join not needed. return with EBUSY if the mutex is already
Threads not joined are called detached locked – might find a use in overcoming
threads. When detached threads terminate, deadlock. 29.
they are destroyed and their resource 30Semaphores A positive integer
released. 10. (including zero) operated upon by two
11Pthreads Detached Threads. 11. operations: P operation on semaphore s
12Issues in writing shared memory Waits until s is greater than zero and
programs. 8a-12. then decrements s by one and allows the
13Interleaved Statements Instructions of process to continue. V operation on
processes/threads interleaved in time. semaphore s Increments s by one and
Example Process/Thread 1 Process/Thread 2 releases one of the waiting processes (if
Instruction 1.1 Instruction 2.1 any). 30.
Instruction 1.2 Instruction 2.2 31P and V operations are performed
Instruction 1.3 Instruction 2.3 Many indivisibly. Mechanism for activating
possible orderings, e.g.: Instruction 1.1 waiting processes implicit in P and V
Instruction 1.2 Instruction 2.1 operations. Though exact algorithm not
Instruction 1.3 Instruction 2.2 specified, algorithm expected to be fair.
Instruction 2.3 assuming instructions Processes delayed by P(s) are kept in
cannot be divided into smaller steps. Each abeyance until released by a V(s) on the
process/thread must achieve the desired same semaphore. Devised by Dijkstra in
results irrespective of the interleaving 1968. Letter P from Dutch word passeren,
order. 13. meaning “to pass” Letter V from Dutch word
14Thread-Safe Routines Thread safe if vrijgeven, meaning “to release”. 31.
routine can be called from multiple 32Mutual exclusion of critical sections
threads simultaneously and always produce can be achieved with one semaphore having
correct results. Standard I/O thread safe the value 0 or 1 (a binary semaphore),
(prints messages without interleaving the which acts as a lock variable, but P and V
characters). System routines that return operations include a process scheduling
time may not be thread safe. Routines that mechanism: Process 1 Process 2 Process 3
access shared data may require special Noncritical section Noncritical section
care to be made thread safe. 14. Noncritical section … ... … P(s) P(s) P(s)
152. Re-ordering code Static re-ordering Critical section Critical section Critical
- Compilers may re-order code during section V(s) V(s) V(s) … … … Noncritical
compilation and prior to execution of code section Noncritical section Noncritical
Dynamic re-ordering - Processors may section. 32.
re-order code during execution. In both 33General semaphore (or counting
cases, objective is to best utilize semaphore) Can take on positive values
available computer resources and minimize other than zero and one. Provide, for
execution time. 8a-15. example, a means of recording number of
16Compiler/Processor Optimizations “resource units” available or used. Can
Compiler and processor reorder solve producer/ consumer problems - more
instructions to improve performance. on that in operating system courses.
Example Suppose one had the code: a = b + Semaphore routines exist for UNIX
5; x = y * 4; p = x + 9; and processor can processes. Does not exist in Pthreads as
perform, as is usual, multiple arithmetic such, though they can be written. Do exist
operations at the same time. Can reorder in real-time extension to Pthreads. 33.
to: x = y * 4; a = b + 5; p = x + 9; and 34Monitor Suite of procedures that
still be logically correct. This gives provides only way to access shared
multiply operation longer time to complete resource. Only one process can use a
before result (x) is needed in last monitor procedure at any instant. Could be
statement. Very common for processors to implemented using a semaphore or lock to
execute machines instructions “out of protect entry, i.e.: monitor_proc1() {
program order” for increased speed. 16. lock(x); monitor body unlock(x); return;
173. Accessing Shared Data Accessing }. A version of a monitor exists in Java
shared data needs careful control. threads, see later. 34.
Consider two processes each of which is to 35Program example To sum the elements of
add one to a shared data item, x. Location an array, a[1000]: int sum, a[1000]; sum =
x is read, x + 1 computed, and the result 0; for (i = 0; i < 1000; i++) sum = sum
written back to the location: 17. + a[i]; 35.
18Instruction Process/thread 1 36Pthreads program example. n threads
Process/thread 2 x = x + 1; read x compute created, each taking numbers from list to
x + 1 write to x read x compute x + 1 add to their local partial sums. When all
write to x. Get x = x + 2 finally. numbers taken, threads can add their
Instruction Process/thread 1 partial sums to a shared location sum.
Process/thread 2 x = x + 1; read x read x Shared location global_index used by each
compute x + 1 compute x + 1 write to x thread to select next element of a[].
write to x. Get x = x + 1 finally. 8a-18. After global_index read, it is incremented
19Critical Section A mechanism for in preparation for next element to be
ensuring that only one process accesses a read. Modified within critical sections.
particular resource at a time. critical 36.
section – a section of code for accessing 3737.
resource Arrange that only one such 3838.
critical section is executed at a time. 39Questions. 8a-39.
This mechanism is known as mutual
Programming with Shared Memory Threads Accessing shared data Critical sections.ppt
http://900igr.net/kartinka/anglijskij-jazyk/programming-with-shared-memory-threads-accessing-shared-data-critical-sections-108798.html
cсылка на страницу

Programming with Shared Memory Threads Accessing shared data Critical sections

другие презентации на тему «Programming with Shared Memory Threads Accessing shared data Critical sections»

«Data Mining» - Data Mining не может заменить аналитика! Визуализация инструментов Data Mining. Data Mining. Критерии: Точность распознавания Ошибка. Примеры использования и реализации. Процесс конструирования. Способствующие факторы. Кибернетические методы. Кросс-проверка - известный метод получения оценок неизвестных параметров модели.

«ГИА по английскому языку 2013» - Примерная тематика заданий. Типы заданий. Структура экзамена. ГИА в 9 классе по английскому языку в 2013 году. На Городском уровне школьники проходят Дистанционную Подготовку к ГИА. Примерный график проведения ГИА по английскому языку. Письмо. Ученики готовятся к сдаче ГИА на основе учебной рабочей программы.

«Музыкальные презентации» - План. Роль музыкальных и песенных презентаций на уроке английского языка. Разучивание мелодии. Критерии отбора песен для музыкальных презентаций. Музыкальные и песенные презентации. Цели. Социокультурный аспект и его учёт в обучении английскому языку. Роль. Фонетическая отработка текста песни. Методика работы с песенными презентациями.

«Winter» - We can play hockey. We go to sledge, ski and skate. I like winter! In winter we have long holidays. In winter there are many funny games. Play snowballs Ski Skate Make snowman. I like winter because it’s snowy and frosty. I think winter is the best. In winter I like to ski with my father (mother, sister, friends).

«ГИА в 9 классе по английскому языку» - Объем текстов для чтения — 250–500 слов. Норма оценок. Максимальное количество баллов за устную часть – 15. За верное выполнение каждого задания с кратким ответом -1 балл. Время выполнения - 30 минут. Для подготовки к ответу на задания С2 и С3 ученику дается 10 минут. Время выполнения – 30 минут. На выполнение письменной части отводится 120 мин.

«English» - ? I study English because… I think so too! English. Why study English? difficult. * Why does Hans learn English? V.I. Lenin. Listening. official. * Сan michael speak english well? I can’t agree with you. Do you like English? main. I can’t but agree with you! Reasons. powerful. No, you are wrong. international.

Без темы

661 презентация
Урок

Английский язык

29 тем
Картинки
900igr.net > Презентации по английскому языку > Без темы > Programming with Shared Memory Threads Accessing shared data Critical sections