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