MCP-S11-07 - LECTURE 7 SYNCHRONIZED DATA STRUCTURES NYU...

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

View Full Document Right Arrow Icon

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

View Full DocumentRight Arrow Icon

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

View Full DocumentRight Arrow Icon

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

View Full DocumentRight Arrow Icon

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

View Full DocumentRight Arrow Icon

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

View Full DocumentRight Arrow Icon

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

View Full DocumentRight Arrow Icon

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

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

Unformatted text preview: LECTURE 7 SYNCHRONIZED DATA STRUCTURES NYU Multicore Programming Class, Spring 2011 lerner@cs.nyu.edu 1 OS HW application concurrency support Were going to use atomic instructions to synchronize more complex structures Context 2 NYU Multicore Programming, Spring 2011 Scalable spinning locks Blocking and Non-blocking queues Todays agenda 3 NYU Multicore Programming, Spring 2011 lock(mutex) { while (test-and-set(mutex)) { } } unlock(mutex) { mutex = 0; } Weve seen the simple spinlock before What is the problem with this lock? NYU Multicore Programming, Spring 2011 4 lock(mutex) { while (test-and-set(mutex)) { } } unlock(mutex) { mutex = 0; } Every thread is implicitly issuing read-to-owns on mutex, even when they wont issue the write to it. A simple spinlock What is the problem with this lock? NYU Multicore Programming, Spring 2011 5 CPU CPU CPU X atomic Invalidate traffic Every test to grab lock involve coherence traffic Can we do better? 6 NYU Multicore Programming, Spring 2011 Trying back-off in between a failed test to aquire the lock and the next attempt Spinning could be done in a way so not to generate too much coherence traffice Ideas We can use something more elaborate than a boolean to represent a locks state 7 NYU Multicore Programming, Spring 2011 State: uint next_ticket uint now_serving The Ticket Lock Intuition NYU Multicore Programming, Spring 2011 8 State: uint next_ticket = 12 uint now_serving = 8 8 11 10 9 Spinning threads testing ticket = ow_serving The Ticket Lock Intuition NYU Multicore Programming, Spring 2011 9 running thread my_ticket == now_serving State: uint next_ticket = 12 uint now_serving = 8 9 11 10 9 Spinning threads testing ticket = ow_serving The Ticket Lock Intuition NYU Multicore Programming, Spring 2011 10 Exit critical section my_ticket == now_serving next running thread State: uint next_ticket = 0 uint now_serving = 0 lock(mutex) { uint my_ticket = fetch_and_add(&mutex->next_ticket) loop sleep( my_ticket - mutex->now_serving) if (my_ticket == mutex->now_serving) return } The Ticket Lock NYU Multicore Programming, Spring 2011 11 unlock(mutex) { mutex->now_serving += 1 } State: uint next_ticket = 0 uint now_serving = 0 lock(mutex) { uint my_ticket = fetch_and_add(&mutex->next_ticket) loop sleep( my_ticket - mutex->now_serving) if (my_ticket == mutex->now_serving) return } Every thread does a read- wn for next ticket The Ticket Lock NYU Multicore Programming, Spring 2011 12 unlock(mutex) { mutex->now_serving += 1 } to-own for next ticket State: uint next_ticket = 0 uint now_serving = 0 lock(mutex) { uint my_ticket = fetch_and_add(&mutex->next_ticket) loop sleep( f( my_ticket - mutex->now_serving) ) if (my_ticket == mutex->now_serving) return } ut the spinning is done The Ticket Lock NYU Multicore Programming, Spring 2011 13 unlock(mutex) { mutex->now_serving += 1 } But the spinning is done on addresses that should be shared or local State: uint next_ticket = 0 uint now_serving = 0...
View Full Document

Page1 / 50

MCP-S11-07 - LECTURE 7 SYNCHRONIZED DATA STRUCTURES NYU...

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

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