dm_thread Module

Abstraction layer of POSIX threads. Has to be linked with -lpthread.

The thread routine must match the C-interoperable abstract interface dm_thread_callback(arg), for example:

subroutine thread_callback(arg) bind(c)
    !! C-interoperable POSIX thread routine.
    use, intrinsic :: iso_c_binding
    type(c_ptr), intent(in), value :: arg !! C pointer to client data.
    integer, pointer               :: i   !! Fortran pointer to client data.

    if (.not. c_associated(arg)) return
    call c_f_pointer(arg, i)
    print '("value: ", i0)', i
end subroutine thread_callback

The dummy argument arg can be of any type. The thread routine and the argument have to be passed to the create function:

integer, target   :: arg
integer           :: rc
type(thread_type) :: thread

arg = 123

rc = dm_thread_create(thread, thread_callback, arg)
rc = dm_thread_join(thread)

The functions return E_SYSTEM on error.


Uses

  • module~~dm_thread~~UsesGraph module~dm_thread dm_thread module~dm_error dm_error module~dm_thread->module~dm_error unix unix module~dm_thread->unix module~dm_ascii dm_ascii module~dm_error->module~dm_ascii module~dm_kind dm_kind module~dm_error->module~dm_kind iso_fortran_env iso_fortran_env module~dm_kind->iso_fortran_env

Used by

  • module~~dm_thread~~UsedByGraph module~dm_thread dm_thread module~dmpack dmpack module~dmpack->module~dm_thread

Abstract Interfaces

abstract interface

  • public subroutine dm_thread_callback(arg) bind(c)

    C-interoperable POSIX thread routine.

    Arguments

    Type IntentOptional Attributes Name
    type(c_ptr), intent(in), value :: arg

    Client data as C pointer.


Derived Types

type, public ::  thread_type

Opaque POSIX thread type.


Functions

public function dm_thread_create(thread, callback, arg) result(rc)

Creates POSIX thread. The function returns E_SYSTEM on error.

Arguments

Type IntentOptional Attributes Name
type(thread_type), intent(out) :: thread

Thread type.

procedure(dm_thread_callback) :: callback

Callback procedure of POSIX thread.

type(*), intent(inout), target :: arg

Client data to be passed to thread procedure.

Return Value integer

public function dm_thread_join(thread, value) result(rc)

Join POSIX thread, and optionally returns value as C pointer.

Arguments

Type IntentOptional Attributes Name
type(thread_type), intent(inout) :: thread

Thread type.

type(c_ptr), intent(out), optional :: value

Returned thread value.

Return Value integer