@@ -906,67 +906,6 @@ The fold method can be useful in the count_collection_iterator function.
906
906
For a further challenge, consult the documentation for Iterator to find
907
907
a different method that could make your code more compact than using fold."""
908
908
909
- # THREADS
910
-
911
- [[exercises ]]
912
- name = " threads1"
913
- path = " exercises/threads/threads1.rs"
914
- mode = " compile"
915
- hint = """
916
- `JoinHandle` is a struct that is returned from a spawned thread:
917
- https://doc.rust-lang.org/std/thread/fn.spawn.html
918
-
919
- A challenge with multi-threaded applications is that the main thread can
920
- finish before the spawned threads are completed.
921
- https://doc.rust-lang.org/book/ch16-01-threads.html#waiting-for-all-threads-to-finish-using-join-handles
922
-
923
- Use the JoinHandles to wait for each thread to finish and collect their results.
924
- https://doc.rust-lang.org/std/thread/struct.JoinHandle.html
925
- """
926
-
927
- [[exercises ]]
928
- name = " threads2"
929
- path = " exercises/threads/threads2.rs"
930
- mode = " compile"
931
- hint = """
932
- `Arc` is an Atomic Reference Counted pointer that allows safe, shared access
933
- to **immutable** data. But we want to *change* the number of `jobs_completed`
934
- so we'll need to also use another type that will only allow one thread to
935
- mutate the data at a time. Take a look at this section of the book:
936
- https://doc.rust-lang.org/book/ch16-03-shared-state.html#atomic-reference-counting-with-arct
937
- and keep reading if you'd like more hints :)
938
-
939
-
940
- Do you now have an `Arc` `Mutex` `JobStatus` at the beginning of main? Like:
941
- `let status = Arc::new(Mutex::new(JobStatus { jobs_completed: 0 }));`
942
- Similar to the code in the example in the book that happens after the text
943
- that says "We can use Arc<T> to fix this.". If not, give that a try! If you
944
- do and would like more hints, keep reading!!
945
-
946
-
947
- Make sure neither of your threads are holding onto the lock of the mutex
948
- while they are sleeping, since this will prevent the other thread from
949
- being allowed to get the lock. Locks are automatically released when
950
- they go out of scope.
951
-
952
- If you've learned from the sample solutions, I encourage you to come
953
- back to this exercise and try it again in a few days to reinforce
954
- what you've learned :)"""
955
-
956
- [[exercises ]]
957
- name = " threads3"
958
- path = " exercises/threads/threads3.rs"
959
- mode = " compile"
960
- hint = """
961
- An alternate way to handle concurrency between threads is to use
962
- a mpsc (multiple producer, single consumer) channel to communicate.
963
- With both a sending end and a receiving end, it's possible to
964
- send values in one thread and receive them in another.
965
- Multiple producers are possible by using clone() to create a duplicate
966
- of the original sending end.
967
- See https://doc.rust-lang.org/book/ch16-02-message-passing.html for more info.
968
- """
969
-
970
909
# SMART POINTERS
971
910
972
911
[[exercises ]]
@@ -1029,6 +968,67 @@ Check out https://doc.rust-lang.org/std/borrow/enum.Cow.html for documentation
1029
968
on the `Cow` type.
1030
969
"""
1031
970
971
+ # THREADS
972
+
973
+ [[exercises ]]
974
+ name = " threads1"
975
+ path = " exercises/threads/threads1.rs"
976
+ mode = " compile"
977
+ hint = """
978
+ `JoinHandle` is a struct that is returned from a spawned thread:
979
+ https://doc.rust-lang.org/std/thread/fn.spawn.html
980
+
981
+ A challenge with multi-threaded applications is that the main thread can
982
+ finish before the spawned threads are completed.
983
+ https://doc.rust-lang.org/book/ch16-01-threads.html#waiting-for-all-threads-to-finish-using-join-handles
984
+
985
+ Use the JoinHandles to wait for each thread to finish and collect their results.
986
+ https://doc.rust-lang.org/std/thread/struct.JoinHandle.html
987
+ """
988
+
989
+ [[exercises ]]
990
+ name = " threads2"
991
+ path = " exercises/threads/threads2.rs"
992
+ mode = " compile"
993
+ hint = """
994
+ `Arc` is an Atomic Reference Counted pointer that allows safe, shared access
995
+ to **immutable** data. But we want to *change* the number of `jobs_completed`
996
+ so we'll need to also use another type that will only allow one thread to
997
+ mutate the data at a time. Take a look at this section of the book:
998
+ https://doc.rust-lang.org/book/ch16-03-shared-state.html#atomic-reference-counting-with-arct
999
+ and keep reading if you'd like more hints :)
1000
+
1001
+
1002
+ Do you now have an `Arc` `Mutex` `JobStatus` at the beginning of main? Like:
1003
+ `let status = Arc::new(Mutex::new(JobStatus { jobs_completed: 0 }));`
1004
+ Similar to the code in the example in the book that happens after the text
1005
+ that says "We can use Arc<T> to fix this.". If not, give that a try! If you
1006
+ do and would like more hints, keep reading!!
1007
+
1008
+
1009
+ Make sure neither of your threads are holding onto the lock of the mutex
1010
+ while they are sleeping, since this will prevent the other thread from
1011
+ being allowed to get the lock. Locks are automatically released when
1012
+ they go out of scope.
1013
+
1014
+ If you've learned from the sample solutions, I encourage you to come
1015
+ back to this exercise and try it again in a few days to reinforce
1016
+ what you've learned :)"""
1017
+
1018
+ [[exercises ]]
1019
+ name = " threads3"
1020
+ path = " exercises/threads/threads3.rs"
1021
+ mode = " compile"
1022
+ hint = """
1023
+ An alternate way to handle concurrency between threads is to use
1024
+ a mpsc (multiple producer, single consumer) channel to communicate.
1025
+ With both a sending end and a receiving end, it's possible to
1026
+ send values in one thread and receive them in another.
1027
+ Multiple producers are possible by using clone() to create a duplicate
1028
+ of the original sending end.
1029
+ See https://doc.rust-lang.org/book/ch16-02-message-passing.html for more info.
1030
+ """
1031
+
1032
1032
# MACROS
1033
1033
1034
1034
[[exercises ]]
0 commit comments