Bugs in the Beta book


#1

Hi i’m learning rust and i’m reading for the second time the book

i have found one little “bug”

In the chapter 16

https://doc.rust-lang.org/beta/book/second-edition/ch16-01-threads.html

I have a problem when i try the first example with threads,… i don’t see the spawned thread when i try it in the browser
I have tried the example in rust playground and i have found the same mistake

I supose that if i run this code in a real machine i will see the println! of the spawned thread

Second little bug is that in a chapter i have seen this is explicated in chapter X,… i don’t remember the chapter with this mistake

Many thanks,


#2

It’s probably due to the way the playground runs on limited resources.
Once main ends, the other thread is killed. Due to the Playground environment however, the second thread never gets scheduled.
If you explicitely wait for the thread to finish, you’ll see its output. See the changed code.

I don’t understand your second issue. If you can elaborate and point to what you mean, we’re happy to help!


#3

I’m not too surprised, starting threads and taking locks (println! macro does that implicitly) takes time, and leaving main automatically terminates all threads. In short, a race condition. The book says:

If you always only see one thread, or if you don’t see any overlap, try increasing the numbers in the ranges to create more opportunities for a thread to take a break and give the other thread a turn.

I multiplied end value by 100, and got this.

hi number 282 from the main thread!
hi number 1 from the spawned thread!

It took me 282 messages on unoptimized build for spawned thread messages to appear. This will depend on operating system, and threading strategy used (in my example, this was 8 core CPU running Arch Linux with kernel version 4.11.2).

That said, it could be made cleaner, I suppose.


#4

I have seen that if i wait the thread to finish i see the println of the main thread and the spawn

But when i wait for the thread to finish (because of playground) i don’t see the two thread at the same time
I always see first the main and after the spawned…

The “problem” is that i see a message that don’t correspond to the examples of the book… (always because playground)

The second “problem” is that i have read in a chapter “This was explicated in chapter X”, in others parts of the manual it’s says “This was explicated in chapter 9” “This was explicated in chapter 13”, a little typo.


#5

Yes, unfortunately that example won’t always work on the playground, as others have explained. Sorry about that!

C:\Users\steve\src\book [master ≡]> git grep "Chapter X"
second-edition/nostarch/chapter01.md:Rust macros in more detail in Chapter XX, but for now you just need to know
second-edition/nostarch/chapter02.md:ecosystem that Chapter XX will discuss, but for
second-edition/nostarch/chapter02.md:will be covered in detail in Chapter 6 and Chapter XX, respectively.
second-edition/nostarch/chapter13.md:about associated types in depth in Chapter XX. For now, all you need to know is
second-edition/nostarch/chapter13.md:we'll be covering them in Chapter XX.
second-edition/style-guide.md:  * This includes all "Chapter XX" intra-book links, which *should* be links

We did this while we were writing the book since we didn’t know where some things were, but but now, have fixed all of them. This is on the latest master of the book; as you can see, the last result is in the “Style guide” which explains this situation, and the rest are in nostarch, which is sometimes out of date.

Thanks for mentioning these things; feel free to report them on the issue tracker in the future: https://github.com/rust-lang/book/issues/new