Lecture-6

Lecture-6 - Principles of Concurrency and Parallelism...

Info iconThis preview shows pages 1–8. Sign up to view the full content.

View Full Document Right Arrow Icon
CS390C: Principles of Concurrency and Parallelism Principles of Concurrency and Parallelism Lecture 6: Posix 2/7/12 Tuesday, February 14, 12
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
CS390C: Principles of Concurrency and Parallelism Shared Memory Threads communicate by reading and writing to shared memory Easier transition from sequential programs Don’t have to construct new communication abstractions But, implicit communication via shared-memory raises complex issues of its own Data races: concurrent (unintended) access to the same memory location How do we express concurrency and synchronization? As language primitives (Java, C#, . ..) As library calls (Posix (Pthreads), Intel TBB) Tuesday, February 14, 12
Background image of page 2
CS390C: Principles of Concurrency and Parallelism Abstraction 3 Shared Memory Every thread can observe actions of other threads on non- thread-local data (e.g., heap) Data visible to multiple threads must be protected ( synchronized ) to ensure the absence of data races A data race consists of two concurrent accesses to the same shared data by two separate threads, at least one of which is a write Thread safety Suppose a program creates n threads, each of which calls the same procedure found in some library Suppose the library modiFes some global (shared) data structure Concurrent modiFcations to this structure may lead to data corruption Tuesday, February 14, 12
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
CS390C: Principles of Concurrency and Parallelism PThreads 4 Exist within a process But, independent control fow share common process resources (like the heap and Fle descriptors) changes made by one thread visible to others pointers have meaning across threads two threads can concurrently read and write to the same memory location Maintain their own stack pointer Registers Pending and blocked signals Can be scheduled by the operating system Tuesday, February 14, 12
Background image of page 4
CS390C: Principles of Concurrency and Parallelism Structure 5 Programs can be decomposed into discrete (mostly) independent tasks The points where they overlap should be easily discerned and amenable for protection Three basic structures master-worker (agenda or blackboard) result-oriented (datafow) pipeline-oriented (specialist) Tuesday, February 14, 12
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
CS390C: Principles of Concurrency and Parallelism API Four major groups Management (create, destroy, join, . ..) Mutexes (synchronization) Condition variables (synchronization defned in terms o± programmer-specifed conditions) Barriers include pthread.h header to gain access to Pthreads operations 6 Tuesday, February 14, 12
Background image of page 6
CS390C: Principles of Concurrency and Parallelism Thread Creation 7 Initially, your main() program comprises a single, default thread. pthread_create creates a new thread and makes it executable. This routine can be called any number of times from anywhere within your code.
Background image of page 7

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 8
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 03/26/2012 for the course CS 390 taught by Professor Staff during the Spring '08 term at Purdue.

Page1 / 34

Lecture-6 - Principles of Concurrency and Parallelism...

This preview shows document pages 1 - 8. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online