Skip to content

vkondratiuk482/thread-pool

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Thread Pool

The main idea is to get familiar with multithreading & implement ThreadPool from scratch

Techniques

Thread-safety is achieved with:

  • Mutex - locking access to shared data and preventing race conditions
  • Conditional variables - wait / signal threads in order to prevent CPU burning (with endless while loops)

Initialization

Unlike the implementation from the standard library, this one doesn't need to be explicitly initialized with undefined before calling the constructor, so this:

var pool: Pool = undefined;
_ = try pool.init(opt);
defer pool.deinit();

Becomes this

var pool = try ThreadPool.init(opt);
defer pool.deinit();

Deinitialization

Deinitialization signals all threads to stop processing new tasks after they finish the current pile in the queue. Then we wait for each thread to finish processing and eventually break the loop and die

TODO

References

About

thread pool implementation in zig

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages