From ff94ef92542fcd1eec9ff84088d5a009a134b1e6 Mon Sep 17 00:00:00 2001 From: Seamus Connor <seamushc@gmail.com> Date: Mon, 8 Feb 2016 14:13:45 -0700 Subject: [PATCH] Moved away from deprecated thread::sleep_ms Refactored to use thread::sleep and time::Duration and updated link in README.md --- .README.md.swp | Bin 0 -> 53248 bytes README.md | 2 +- threads/threads1.rs | 5 +++-- 3 files changed, 4 insertions(+), 3 deletions(-) create mode 100644 .README.md.swp diff --git a/.README.md.swp b/.README.md.swp new file mode 100644 index 0000000000000000000000000000000000000000..1019b281b567bd5e01a894eaef2ba392a5ce7309 GIT binary patch literal 53248 zcmeI5TZ|lOme*^TT^1H*XJ!X2NU%$K8t=3nQ{{4&-F6QQt#a9(_RzK)m%E$BJ=8>I zMporGGb1}9)8!g*dEla5BrXC8ad`k9Kmrzt;fdP=Xci=d5X%clydikw1q9-O9T30& zIo}r%nUz(pvd8Y3*(z1!Exzmd&UfzTi_ZG{ckZ^XtzB8+?{h0FKlc;=`29co>B*=5 z)4|G0+0Dn}ywIIv|0V~+e0*#PzxhW)gO`eIl9!hzSyATWba<(lmDAy1yjxy+aBK7C z-CJv;-U(VeD{=;bGYFg*0<&p<_4;R4HrkihRp+%Yo@;&Kr{6nq^|OL!5IBRt83fKC za0Y=h2%JIS3<75mID^0sKLn<epIrH4Oyk#usr-)c{;7rc9}nMuGQ9un!u?+#zW-Qw z|I)(!p9tT7b9he{?*E4H{inkFwT1h?apC^0h5K<_aUR<X_kUCP{+aL|HJ>=oIIh@# zXQBS5!}rgJ_epq<{e`b*Z)XrVgTNUC&LD6Gfino4LEsDmXAn4pz!?P2AaDkOA4mwK zxY~0@_Ny8l{{N`||F6%kto%=|Kgm^aeaw|`UF7;a*XOvtfwKG&*S|!m{$;K&phW*P z*Y{Aif0gSOxqgA`-=MsI2LnMD<G>RX?itrESD)*9q3{2r{$KImqX*eAdy<Z)t?phr znPx?6Fm65E%UTZzNNBxV<hw;W8WEV#dM6$4&eGlN8?Wz8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%S3>w3B>p}$zFR1ziScoaob z=~fZU`!YRody5de1|HSE$|c>arZq|iJ?+j_<ebw%_2d>6Z2sBv%~a*;;i0%N+$_Cl z71(ATplX105YyQw{>f|~TM-!I{bVOc|7vVjoyb=)A2Ax%!m!#_UCY>9GueQ5IL#El z))MQ5W6GK;`2Drnc)v)owbrRf8bA>DU)<W@vUGGx&0{v3*fLy9n$p(eyPb)k9UgX4 zkVV}A<9081F9C?!w!n$$NJ%vT616zc0?g3~RYzh+IIT}|iX?`D^SIIUNTD3-;UyXt zc`y^ReE1nG0AIfbQCix98T6{LEon9yH<a6xbP42$xez=^qN_1CXCKvaeoh-RHiES3 ziAZs(jcUON@^FDeJwIoPnLs23;n>QaV4QXSgja}Bf79(9uB1FKhf;RD`8{P5dUhO` zr_|$}80hij*WcB-Ug_}G$1L*AtTVG*2|K{pZNkaBA+`QqKK^!A<aaPk`%x~lH?CBh z%s{O3k5ABUriAY;Qx5X+Epo)*o)z`G7tSzXG-1d7K|1wsl`1{p>FGy|tI-tf#&aGm zB}Urzz((vL+YekZ+}Jv5ep~ZnG<H-CQ(Im6Ki7|{eckhL@MZ-tL5`gNEK&%|Z?8`{ zVAT4u<9kwGsRe4(Ov^r^ck_|>+?74|rk*8`YqX1W(c7{^sj<RdXEAu4TN-Ed^{SW; z_}SgATE7)~2wW%a%h&sa{aAEOr1TYj2pdoS@01pT^Q>t>WhJo<71+?EnbQ14Z&E$G zNdlca!6hXk(a|uNLS5hG4Zp=5Nh~p3-whm=7S>f3J+(!47n{-&Rc-kriF0zntO{qf z*wN;m<(Q92o~Y>QVmr+t9creR!3IYPcrz=9>^GHZTMsqU!$A=zLTo8kV<VWhm0NF% txia{Z(#%W*VAa?wwHj)|qpx8(;>jiDNn6?t<wF~R^pZANWDVl`{{bAp<Q4z` literal 0 HcmV?d00001 diff --git a/README.md b/README.md index 5e99bf2..062adfe 100644 --- a/README.md +++ b/README.md @@ -109,7 +109,7 @@ The [Concurrency](https://doc.rust-lang.org/stable/book/concurrency.html) sectio See [the Dining Philosophers example](https://doc.rust-lang.org/stable/book/dining-philosophers.html) and the [Concurrency Chapter](https://doc.rust-lang.org/stable/book/concurrency.html) from the book. -- ["threads1.rs"](http://play.rust-lang.org/?code=%2F%2F+Make+this+compile%21+Scroll+down+for+hints+%3A%29+The+idea+is+the+thread%0A%2F%2F+spawned+on+line+17+is+completing+jobs+while+the+main+thread+is%0A%2F%2F+monitoring+progress+until+10+jobs+are+completed.+If+you+see+6+lines%0A%2F%2F+of+%22waiting...%22+and+the+program+ends+without+timing+out+the+playground%2C%0A%2F%2F+you%27ve+got+it+%3A%29%0A%0Ause+std%3A%3Async%3A%3AArc%3B%0Ause+std%3A%3Athread%3B%0A%0Astruct+JobStatus+%7B%0A++++jobs_completed%3A+u32%2C%0A%7D%0A%0Afn+main%28%29+%7B%0A++++let+status+%3D+Arc%3A%3Anew%28JobStatus+%7B+jobs_completed%3A+0+%7D%29%3B%0A++++let+status_shared+%3D+status.clone%28%29%3B%0A++++thread%3A%3Aspawn%28move+%7C%7C+%7B%0A++++++++for+_+in+0..10+%7B%0A++++++++++++thread%3A%3Asleep_ms%28250%29%3B%0A++++++++++++status_shared.jobs_completed+%2B%3D+1%3B%0A++++++++%7D%0A++++%7D%29%3B%0A++++while+status.jobs_completed+%3C+10+%7B%0A++++++++println%21%28%22waiting...+%22%29%3B%0A++++++++thread%3A%3Asleep_ms%28500%29%3B%0A++++%7D%0A%7D%0A%0A%0A%0A%0A%0A%0A%0A%0A%0A%0A%0A%0A%0A%0A%2F%2F+%60Arc%60+is+an+Atomic+Reference+Counted+pointer+that+allows+safe%2C+shared+access%0A%2F%2F+to+**immutable**+data.+But+we+want+to+*change*+the+number+of+%60jobs_completed%60%0A%2F%2F+so+we%27ll+need+to+also+use+another+type+that+will+only+allow+one+thread+to%0A%2F%2F+mutate+the+data+at+a+time.+Take+a+look+at+this+section+of+the+book%3A%0A%2F%2F+https%3A%2F%2Fdoc.rust-lang.org%2Fstable%2Fbook%2Fconcurrency.html%23safe-shared-mutable-state%0A%2F%2F+and+keep+scrolling+if+you%27d+like+more+hints+%3A%29%0A%0A%0A%0A%0A%0A%0A%0A%0A%0A%0A%2F%2F+Do+you+now+have+an+%60Arc%60+%60Mutex%60+%60JobStatus%60+at+the+beginning+of+main%3F+Like%3A%0A%2F%2F+%60let+status+%3D+Arc%3A%3Anew%28Mutex%3A%3Anew%28JobStatus+%7B+jobs_completed%3A+0+%7D%29%29%3B%60%0A%2F%2F+Similar+to+the+code+in+the+example+in+the+book+that+happens+after+the+text%0A%2F%2F+that+says+%22We+can+use+Arc%3CT%3E+to+fix+this.%22.+If+not%2C+give+that+a+try%21+If+you%0A%2F%2F+do+and+would+like+more+hints%2C+keep+scrolling%21%21%0A%0A%0A%0A%0A%0A%0A%0A%0A%0A%0A%0A%0A%2F%2F+Make+sure+neither+of+your+threads+are+holding+onto+the+lock+of+the+mutex%0A%2F%2F+while+they+are+sleeping%2C+since+this+will+prevent+the+other+thread+from%0A%2F%2F+being+allowed+to+get+the+lock.+Locks+are+automatically+released+when%0A%2F%2F+they+go+out+of+scope.%0A%0A%2F%2F+Ok%2C+so%2C+real+talk%2C+this+was+actually+tricky+for+*me*+to+do+too.+And%0A%2F%2F+I+could+see+a+lot+of+different+problems+you+might+run+into%2C+so+at+this%0A%2F%2F+point+I%27m+not+sure+which+one+you%27ve+hit+%3A%29+Please+see+a+few+possible%0A%2F%2F+answers+on+https%3A%2F%2Fgithub.com%2Fcarols10cents%2Frustlings%2Fissues%2F3+--%0A%2F%2F+mine+is+a+little+more+complicated+because+I+decided+I+wanted+to+see%0A%2F%2F+the+number+of+jobs+currently+done+when+I+was+checking+the+status.%0A%0A%2F%2F+Please+open+an+issue+if+you%27re+still+running+into+a+problem+that%0A%2F%2F+these+hints+are+not+helping+you+with%2C+or+if+you%27ve+looked+at+the+sample%0A%2F%2F+answers+and+don%27t+understand+why+they+work+and+yours+doesn%27t.%0A%0A%2F%2F+If+you%27ve+learned+from+the+sample+solutions%2C+I+encourage+you+to+come%0A%2F%2F+back+to+this+exercise+and+try+it+again+in+a+few+days+to+reinforce%0A%2F%2F+what+you%27ve+learned+%3A%29%0A) +- ["threads1.rs"](<https://play.rust-lang.org/?code=%2F%2F%20Make%20this%20compile!%20Scroll%20down%20for%20hints%20%3A\)%20The%20idea%20is%20the%20thread%0A%2F%2F%20spawned%20on%20line%2017%20is%20completing%20jobs%20while%20the%20main%20thread%20is%0A%2F%2F%20monitoring%20progress%20until%2010%20jobs%20are%20completed.%20If%20you%20see%206%20lines%0A%2F%2F%20of%20%22waiting...%22%20and%20the%20program%20ends%20without%20timing%20out%20the%20playground%2C%0A%2F%2F%20you%27ve%20got%20it%20%3A\)%0A%0Ause%20std%3A%3Async%3A%3AArc%3B%0Ause%20std%3A%3Athread%3B%0Ause%20std%3A%3Atime%3A%3ADuration%3B%0A%0Astruct%20JobStatus%20%7B%0A%20%20%20%20jobs_completed%3A%20u32%2C%0A%7D%0A%0Afn%20main\(\)%20%7B%0A%20%20%20%20let%20status%20%3D%20Arc%3A%3Anew\(JobStatus%20%7B%20jobs_completed%3A%200%20%7D\)%3B%0A%20%20%20%20let%20status_shared%20%3D%20status.clone\(\)%3B%0A%20%20%20%20thread%3A%3Aspawn\(move%20%7C%7C%20%7B%0A%20%20%20%20%20%20%20%20for%20_%20in%200..10%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20thread%3A%3Asleep\(Duration%3A%3Afrom_millis\(250\)\)%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20status_shared.jobs_completed%20%2B%3D%201%3B%0A%20%20%20%20%20%20%20%20%7D%0A%20%20%20%20%7D\)%3B%0A%20%20%20%20while%20status.jobs_completed%20%3C%2010%20%7B%0A%20%20%20%20%20%20%20%20println!\(%22waiting...%20%22\)%3B%0A%20%20%20%20%20%20%20%20thread%3A%3Asleep\(Duration%3A%3Afrom_millis\(500\)\)%3B%0A%20%20%20%20%7D%0A%7D%0A%0A%0A%0A%0A%0A%0A%0A%0A%0A%0A%0A%0A%0A%0A%2F%2F%20%60Arc%60%20is%20an%20Atomic%20Reference%20Counted%20pointer%20that%20allows%20safe%2C%20shared%20access%0A%2F%2F%20to%20**immutable**%20data.%20But%20we%20want%20to%20*change*%20the%20number%20of%20%60jobs_completed%60%0A%2F%2F%20so%20we%27ll%20need%20to%20also%20use%20another%20type%20that%20will%20only%20allow%20one%20thread%20to%0A%2F%2F%20mutate%20the%20data%20at%20a%20time.%20Take%20a%20look%20at%20this%20section%20of%20the%20book%3A%0A%2F%2F%20https%3A%2F%2Fdoc.rust-lang.org%2Fstable%2Fbook%2Fconcurrency.html%23safe-shared-mutable-state%0A%2F%2F%20and%20keep%20scrolling%20if%20you%27d%20like%20more%20hints%20%3A\)%0A%0A%0A%0A%0A%0A%0A%0A%0A%0A%0A%2F%2F%20Do%20you%20now%20have%20an%20%60Arc%60%20%60Mutex%60%20%60JobStatus%60%20at%20the%20beginning%20of%20main%3F%20Like%3A%0A%2F%2F%20%60let%20status%20%3D%20Arc%3A%3Anew\(Mutex%3A%3Anew\(JobStatus%20%7B%20jobs_completed%3A%200%20%7D\)\)%3B%60%0A%2F%2F%20Similar%20to%20the%20code%20in%20the%20example%20in%20the%20book%20that%20happens%20after%20the%20text%0A%2F%2F%20that%20says%20%22We%20can%20use%20Arc%3CT%3E%20to%20fix%20this.%22.%20If%20not%2C%20give%20that%20a%20try!%20If%20you%0A%2F%2F%20do%20and%20would%20like%20more%20hints%2C%20keep%20scrolling!!%0A%0A%0A%0A%0A%0A%0A%0A%0A%0A%0A%0A%0A%2F%2F%20Make%20sure%20neither%20of%20your%20threads%20are%20holding%20onto%20the%20lock%20of%20the%20mutex%0A%2F%2F%20while%20they%20are%20sleeping%2C%20since%20this%20will%20prevent%20the%20other%20thread%20from%0A%2F%2F%20being%20allowed%20to%20get%20the%20lock.%20Locks%20are%20automatically%20released%20when%0A%2F%2F%20they%20go%20out%20of%20scope.%0A%0A%2F%2F%20Ok%2C%20so%2C%20real%20talk%2C%20this%20was%20actually%20tricky%20for%20*me*%20to%20do%20too.%20And%0A%2F%2F%20I%20could%20see%20a%20lot%20of%20different%20problems%20you%20might%20run%20into%2C%20so%20at%20this%0A%2F%2F%20point%20I%27m%20not%20sure%20which%20one%20you%27ve%20hit%20%3A\)%20Please%20see%20a%20few%20possible%0A%2F%2F%20answers%20on%20https%3A%2F%2Fgithub.com%2Fcarols10cents%2Frustlings%2Fissues%2F3%20--%0A%2F%2F%20mine%20is%20a%20little%20more%20complicated%20because%20I%20decided%20I%20wanted%20to%20see%0A%2F%2F%20the%20number%20of%20jobs%20currently%20done%20when%20I%20was%20checking%20the%20status.%0A%0A%2F%2F%20Please%20open%20an%20issue%20if%20you%27re%20still%20running%20into%20a%20problem%20that%0A%2F%2F%20these%20hints%20are%20not%20helping%20you%20with%2C%20or%20if%20you%27ve%20looked%20at%20the%20sample%0A%2F%2F%20answers%20and%20don%27t%20understand%20why%20they%20work%20and%20yours%20doesn%27t.%0A%0A%2F%2F%20If%20you%27ve%20learned%20from%20the%20sample%20solutions%2C%20I%20encourage%20you%20to%20come%0A%2F%2F%20back%20to%20this%20exercise%20and%20try%20it%20again%20in%20a%20few%20days%20to%20reinforce%0A%2F%2F%20what%20you%27ve%20learned%20%3A\)%0A&version=stable>) ### Uncategorized diff --git a/threads/threads1.rs b/threads/threads1.rs index c19151e..af97552 100644 --- a/threads/threads1.rs +++ b/threads/threads1.rs @@ -6,6 +6,7 @@ use std::sync::Arc; use std::thread; +use std::time::Duration; struct JobStatus { jobs_completed: u32, @@ -16,13 +17,13 @@ fn main() { let status_shared = status.clone(); thread::spawn(move || { for _ in 0..10 { - thread::sleep_ms(250); + thread::sleep(Duration::from_millis(250)); status_shared.jobs_completed += 1; } }); while status.jobs_completed < 10 { println!("waiting... "); - thread::sleep_ms(500); + thread::sleep(Duration::from_millis(500)); } }