Gjsify LogoGjsify Logo

The #GThreadPool struct represents a thread pool. It has three public read-only members, but the underlying struct is bigger, so you must not copy this struct.

record

Hierarchy

  • ThreadPool

Index

Constructors

Properties

exclusive: boolean

are all threads exclusive to this pool

field
func: GLib.Func

the function to execute in the threads of this pool

field
userData: object

the user data for the threads of this pool

field
name: string

Methods

  • free(immediate: boolean, wait: boolean): void
  • Frees all resources allocated for pool.

    If immediate is %TRUE, no new task is processed for pool. Otherwise pool is not freed before the last task is processed. Note however, that no thread of this pool is interrupted while processing a task. Instead at least all still running threads can finish their tasks before the pool is freed.

    If wait_ is %TRUE, this function does not return before all tasks to be processed (dependent on immediate, whether all or only the currently running) are ready. Otherwise this function returns immediately.

    After calling this function pool must not be used anymore.

    Parameters

    • immediate: boolean

      should pool shut down immediately?

    • wait: boolean

      should the function wait for all tasks to be finished?

    Returns void

  • getMaxThreads(): number
  • getNumThreads(): number
  • Returns the number of threads currently running in pool.

    Returns number

  • moveToFront(data: object): boolean
  • Moves the item to the front of the queue of unprocessed items, so that it will be processed next.

    Parameters

    • data: object

      an unprocessed item in the pool

    Returns boolean

  • push(data: object): boolean
  • Inserts data into the list of tasks to be executed by pool.

    When the number of currently running threads is lower than the maximal allowed number of threads, a new thread is started (or reused) with the properties given to g_thread_pool_new(). Otherwise, data stays in the queue until a thread in this pool finishes its previous task and processes data.

    error can be %NULL to ignore errors, or non-%NULL to report errors. An error can only occur when a new thread couldn't be created. In that case data is simply appended to the queue of work to do.

    Before version 2.32, this function did not return a success status.

    Parameters

    • data: object

      a new task for pool

    Returns boolean

  • setMaxThreads(maxThreads: number): boolean
  • Sets the maximal allowed number of threads for pool. A value of -1 means that the maximal number of threads is unlimited. If pool is an exclusive thread pool, setting the maximal number of threads to -1 is not allowed.

    Setting max_threads to 0 means stopping all work for pool. It is effectively frozen until max_threads is set to a non-zero value again.

    A thread is never terminated while calling func, as supplied by g_thread_pool_new(). Instead the maximal number of threads only has effect for the allocation of new threads in g_thread_pool_push(). A new thread is allocated, whenever the number of currently running threads in pool is smaller than the maximal number.

    error can be %NULL to ignore errors, or non-%NULL to report errors. An error can only occur when a new thread couldn't be created.

    Before version 2.32, this function did not return a success status.

    Parameters

    • maxThreads: number

      a new maximal number of threads for pool, or -1 for unlimited

    Returns boolean

  • unprocessed(): number
  • Returns the number of tasks still unprocessed in pool.

    Returns number

  • getMaxIdleTime(): number
  • This function will return the maximum interval that a thread will wait in the thread pool for new tasks before being stopped.

    If this function returns 0, threads waiting in the thread pool for new work are not stopped.

    Returns number

  • getMaxUnusedThreads(): number
  • Returns the maximal allowed number of unused threads.

    Returns number

  • getNumUnusedThreads(): number
  • setMaxIdleTime(interval: number): void
  • This function will set the maximum interval that a thread waiting in the pool for new tasks can be idle for before being stopped. This function is similar to calling g_thread_pool_stop_unused_threads() on a regular timeout, except this is done on a per thread basis.

    By setting interval to 0, idle threads will not be stopped.

    The default value is 15000 (15 seconds).

    Parameters

    • interval: number

      the maximum interval (in milliseconds) a thread can be idle

    Returns void

  • setMaxUnusedThreads(maxThreads: number): void
  • Sets the maximal number of unused threads to max_threads. If max_threads is -1, no limit is imposed on the number of unused threads.

    The default value is 2.

    Parameters

    • maxThreads: number

      maximal number of unused threads

    Returns void

  • stopUnusedThreads(): void
  • Stops all currently unused threads. This does not change the maximal number of unused threads. This function can be used to regularly stop all unused threads e.g. from g_timeout_add().

    Returns void

Legend

  • Module
  • Object literal
  • Variable
  • Function
  • Function with type parameter
  • Index signature
  • Type alias
  • Type alias with type parameter
  • Enumeration
  • Enumeration member
  • Property
  • Method
  • Interface
  • Interface with type parameter
  • Constructor
  • Property
  • Method
  • Index signature
  • Class
  • Class with type parameter
  • Constructor
  • Property
  • Method
  • Accessor
  • Index signature
  • Inherited constructor
  • Inherited property
  • Inherited method
  • Inherited accessor
  • Protected property
  • Protected method
  • Protected accessor
  • Private property
  • Private method
  • Private accessor
  • Static property
  • Static method