Programming for Multi-Core CPUs

Programming for Multi-Core CPUs - Programming for...

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

View Full Document Right Arrow Icon
School of Electrical Engineering and Computer Science University of Central Florida 1 Programming for Multi Programming for Multi -Core CPUs: Core CPUs: Locking and Transactional Memory Locking and Transactional Memory Huiyang Zhou Slides 1-18 are from Professor Umakishore Ramachandran @ GaTech 2 compute compute I/O I/O result Needed (a) Sequential process compute thread I/O result Needed (b) Multithreaded process I/O request I/O complete I/O thread Example use of threads Example use of threads - 1
Background image of page 1

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

View Full DocumentRight Arrow Icon
3 Digitizer Tracker Alarm Example use of threads Example use of threads - 2 4 Programming Support for Threads Programming Support for Threads • creation – pthread_create (top-level procedure, args) • termination – return from top-level procedure – explicit kill • rendezvous – creator can wait for children • pthread_join (child_tid) • synchronization – mutex – condition variables Main thread thread_create(foo, args) (a) Before thread creation main thread thread_create(foo, args) (b) After thread creation foo thread
Background image of page 2
5 Sample program Sample program – thread create/join thread create/join int foo(int n) { ..... return 0; } int main() { int f; thread_type child_tid; ..... child_tid = thread_create (foo, &f); ..... thread_join(child_tid); } 6 Programming with Threads Programming with Threads • synchronization – for coordination of the threads • communication – for inter-thread sharing of data – threads can be in different processors – how to achieve sharing in SMP? • software : accomplished by keeping all threads in the same address space by the OS • hardware : accomplished by hardware shared memory and coherent caches producer consumer buffer
Background image of page 3

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

View Full DocumentRight Arrow Icon
7 Need for Synchronization Need for Synchronization digitizer() { image_type dig_image; int tail = 0; loop { if (bufavail > 0) { grab(dig_image); frame_buf[tail mod MAX] = dig_image; tail = tail + 1; bufavail = bufavail - 1 ; } } } tracker() { image_type track_image; int head = 0; loop { if (bufavail < MAX) { track_image = frame_buf[head mod MAX]; head = head + 1; bufavail = bufavail + 1; analyze(track_image); } } } Problem? 8 digitizer tracker bufavail bufavail = bufavail – 1; bufavail = bufavail + 1; Shared data structure …… head tail (First valid filled frame in frame_buf ) (First empty spot in frame_buf ) 0 99 frame_buf
Background image of page 4
9 Synchronization Primitives Synchronization Primitives • lock and unlock
Background image of page 5

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

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

This note was uploaded on 10/03/2011 for the course CDA 6938 taught by Professor Zou,c during the Spring '08 term at University of Central Florida.

Page1 / 13

Programming for Multi-Core CPUs - Programming for...

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

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