Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Project: Designing a Thread Pool. Project Description: A Thread Pool is a famous design pattern which consists of a number N of threads running a

Project: Designing a Thread Pool.

Project Description: A Thread Pool is a famous design pattern which consists of a number N of threads running a number M of jobs concurrently. The main motivation behind using the pattern is to avoid the overhead associated with creating and destroying threads. The more straight-forward approach of handling M independent jobs would be to spawn a thread for each job and destroy the thread once the job is executed. However, in some use-cases, such as when the number M of jobs is big, and the jobs are relatively small, too many threads will be generated. In modern operating systems creating a thread or a process is an expensive operation, so avoiding it in those use-cases will improve the performance of the system as well as guarantee that the system won't spawn too many processes. Instead of creating a thread for each task, thread pool normally creates threads one time at the beginning and maintains the threads in running/sleeping condition throughout its lifetime. Tasks are passed to the worker threads one by one only when a worker thread is finished with the previous task and can accept a task.

When thread pools are used, a task is submitted to the pool and executed by a thread from the pool. Work is submitted to the pool using a queue, and an available thread removes work from the queue. If there are no available threads, the work remains queued until one becomes available. If there is no work, threads await notification until a task becomes available.

Now your task is to design a thread pool with synchronization between threads.

Note: Code should be in C language and explain the code.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Advanced Database Systems

Authors: Carlo Zaniolo, Stefano Ceri, Christos Faloutsos, Richard T. Snodgrass, V.S. Subrahmanian, Roberto Zicari

1st Edition

155860443X, 978-1558604438

More Books

Students also viewed these Databases questions