MONC
Data Types | Modules | Functions/Subroutines | Variables
threadpool.F90 File Reference

Go to the source code of this file.

Data Types

interface  threadpool_mod::thread_procedure
 The thread call procedure interface. More...
 
type  threadpool_mod::threaded_procedure_container_type
 Wraps the thread procedure with the call itself and the data to pass to it. More...
 

Modules

module  threadpool_mod
 This is a thread pool and the single management "main" thread will spawn out free threads in the pool to perform specific work. If there are no free threads then it will block until one becomes available. It uses ForThreads, which is a wrapper around pthreads. The thread pool works by creating a number of threads and then passing the work to these threads, rather than creating a new thread for each piece of work.
 

Functions/Subroutines

subroutine, public threadpool_mod::threadpool_init (io_configuration)
 Initialises the thread pool and marks each thread as idle. More...
 
subroutine, public threadpool_mod::threadpool_lock_netcdf_access ()
 Aquires the NetCDF thread lock, NetCDF is not thread safe so we need to manage thread calls to it. More...
 
subroutine, public threadpool_mod::threadpool_unlock_netcdf_access ()
 Releases the NetCDF thread lock, NetCDF is not thread safe so we need to manage thread calls to it. More...
 
subroutine, public threadpool_mod::threadpool_start_thread (proc, arguments, data_buffer)
 Starts an idle thread from the pool to execute a specific procedure with some data. If there is no thread available then this will block until one becomes idle. More...
 
subroutine threadpool_mod::threadpool_thread_entry_procedure (thread_id)
 Entry point called by each thread creation in the pool, this calls out to the actual procedure to execute and doing it this way allows us to perform some actions before or after which can help with the management of the pool. More...
 
logical function, public threadpool_mod::threadpool_is_idle ()
 Determines whether the thread pool is idle or not (i.e. all threads are idle and waiting for work) More...
 
subroutine, public threadpool_mod::threadpool_deactivate ()
 This waits for all busy threads to complete and then shuts all the pthreads down. The deactivation and finalisation procedures are split out as we want to deactivate the pool (to ensure no threads are running actions), finalise these actions which might involve destroying mutexes, and then destroying the threading environment in finalisation. More...
 
subroutine, public threadpool_mod::threadpool_finalise ()
 Finalises the thread pool. More...
 
integer function threadpool_mod::find_idle_thread ()
 Finds an idle thread, if one is not available then will block until one becomes free. More...
 
integer function threadpool_mod::get_index_of_idle_thread ()
 Specifically gets the index of the next idle thread or -1 if they are all busy. This starts from a next suggested idle thread and will wrap around, as often the next thread will be idle rather than searching from the beginning again. More...
 
subroutine, public threadpool_mod::check_thread_status (ierr)
 Checks the error status of any thread operation and reports an error if it failed. More...
 

Variables

integer, parameter threadpool_mod::default_thread_pool_size =10
 Number of threads in the pool. More...
 
logical, dimension(:), allocatable, volatile threadpool_mod::thread_busy
 
logical, dimension(:), allocatable, volatile threadpool_mod::thread_start
 
integer, dimension(:), allocatable, volatile threadpool_mod::thread_ids
 
integer, dimension(:), allocatable, volatile threadpool_mod::thread_pass_data
 
integer, dimension(:), allocatable, volatile threadpool_mod::activate_thread_condition_variables
 
integer, dimension(:), allocatable, volatile threadpool_mod::activate_thread_mutex
 
type(threaded_procedure_container_type), dimension(:), allocatable, volatile threadpool_mod::thread_entry_containers
 
integer, volatile threadpool_mod::netcdfmutex
 Mutex used for controling NetCDF access. More...
 
integer, volatile threadpool_mod::next_suggested_idle_thread
 
logical, volatile threadpool_mod::threadpool_active
 
integer, volatile threadpool_mod::active_threads
 
integer, volatile threadpool_mod::total_number_of_threads
 
integer, volatile threadpool_mod::active_scalar_mutex