Skip to content

chinoto/rust_prime

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Rusty Prime Generator

Now with more oxidizers!

My first task in learning a language is to make a prime generator because it's pretty simple, but more complex than "Hello World". This time I did it in a language capable of multi-threading, so I had to try it.

My big problem for awhile was figuring out how to keep the output of the workers in order so that the prime list is sequential and not missing any primes when updated, then I remembered reading The ryg blog: Ring buffers and queues, which solved the issue quite nicely (though I'm probably not using it in a typical way in prime_buffer_mt_ptc.rs).

After that it was mostly just banging my head against the wall trying to figure out the intricacies of Rust, such as using &* to dereference the underlying value of a (read|write)guard and then getting a reference to it (rather than the guard). Thanks to mbrubeck of ##rust on freenode for helping with that, I couldn't find anything at all via search engine.

Files

It is best to read prime.rs, prime_buffer.rs, and then prime_buffer_mt_ptc.rs because I only comment on new aspects to the code in each file.

I tried to keep my file names short, these are what the abbreviations mean:

  • mt = multi-threaded
  • ptc = per thread channel
  • sc = single channel (probably came after ptc)

TODO

  • Try "writing into padding" idea in rayon implementation.
  • Break this into main and worker pieces that can be compiled by Emscripten and spun up in Web Workers.

About

Multithreaded prime generator in Rust

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages