nlhdh_tuan4 - 1 1 Nguyn l h i u hnh Nguy n H i Chu Khoa Cng...

Info iconThis preview shows pages 1–3. 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
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: 1 1 Nguyn l h i u hnh Nguy n H i Chu Khoa Cng ngh thng tin Tr ng i h c Cng ngh 2 ng b ha ti n trnh 3 V d ng b ha (1) Ti n trnh ghi P : while (true) { while (counter==SIZE) ; buf[in] = nextItem; in = (in+1) % SIZE; counter++; } buf: Buffer SIZE: c c a buffer counter: Bi n chung Ti n trnh c Q : while (true) { while (counter==0) ; nextItem = buf[out]; out = (out+1) % SIZE; counter--; } z y l bi ton vng m c gi i h n 4 V d ng b ha (2) z counter++ register 1 = counter; register 1 = register 1 + 1; counter = register 1 ; z counter-- register 2 = counter; register 2 = register 2- 1; counter = register 2 ; z Cc ton t ++ v -- c th c ci t nh sau: P v Q c th nh n c cc gi tr khc nhau c a counter t i cng 1 th i i m n u nh o n m xanh v th c hi n xen k nhau. 5 V d ng b ha (3) z Gi s P v Q th c hi n song song v i nhau v gi tr c a counter l 5: register 1 = counter; // register 1 =5 register 1 = register 1 + 1; // register 1 =6 register 2 = counter; // register 2 =5 register 2 = register 2- 1; // register 2 =4 counter = register 1 ; // counter=6 !! counter = register 2 ; // counter=4 !! 6 V d ng b ha (4) z L i: Cho php P v Q ng th i thaotc trn bi n chung counter . S a l i: register 1 = counter; // register 1 =5 register 1 = register 1 + 1; // register 1 =6 counter = register 1 ; // counter=6 register 2 = counter; // register 2 =6 register 2 = register 2- 1; // register 2 =5 counter = register 2 ; // counter=5 2 7 T ng tranh v ng b z Tnh hu ng xu t hi n khi nhi u ti n trnh cng thao tc trn d li u chung v k t qu cc thao tc ph thu c vo th t th c hi n c a cc ti n trnh trn d li u chung g i l tnh hu ng t ng tranh ( race condition ) z trnh cc tnh hu ng t ng tranh, cc ti n trnh c n c ng b theo m t ph ng th c no V n nghin c u: ng b ha cc ti n trnh 8 Khi ni m v o n m g ng (1) z Thu t ng : Critical section z Thu t ng ti ng Vi t: o n m g ng, o n m t i h n. z Xt m t h c n ti n trnh P , P 1 , ..., P n , m i ti n trnh c m t o n m l nh g i l o n m g ng, k hi u l CS i , n u nh trong o n m ny, cc ti n trnh thao tc trn cc bi n chung, c ghi file... (t ng qut: thao tc trn d li u chung) 9 Khi ni m v o n m g ng (2) z c...
View Full Document

Page1 / 10

nlhdh_tuan4 - 1 1 Nguyn l h i u hnh Nguy n H i Chu Khoa Cng...

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

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