gotoHomeFree Source CodeModule fthreadsFact SheetEmail us |
Purple Sage Computing Solutions, Inc. |
|
Home --> Free Source Code --> fthreads --> fthreads Usage --> fthreads Mutexs fthreads MutexsThis page discusses fthreads mutexs. A list of links is provided below.
IntroductionA mutex is a synchronization object. A mutex may be locked or unlocked. If a mutex is locked by a thread, no other thread may lock it. A mutex may be used to allow only one thread at a time to execute a piece of code, for example, updating a global variable. The code which must be executed by one thread at a time is placed between calls to mutex_lock() and mutex_unlock(). A mutex is initialized by declaring a variable of type mutex_t and passing it to mutex_init(). Type mutex_t is defined in module fthreads. A mutex's statistics may be gathered by mutex_status(). A mutex has a mutex id, which is a unique integer between one and the number passed to fthread_init(). The mutex id may be returned by calling mutex_id(). Mutex Routinesmutex_init()The mutex_init() routine initializes a new mutex synchronization object.
interface
subroutine mutex_init( m, tm, name, &
trace_v, flag)
type( mutex_t), intent( out) :: m
type( team_t), optional, &
intent( in) :: tm
character( len= *), optional, &
intent( in) :: name
type( trace_t), optional, &
intent( inout) :: trace_v
integer, optional, &
intent( out) :: flag
end subroutine mutex_init
end interface
The mutex_init() routine returns a type mutex_t variable m. The mutex is visible to members of optional type team_t variable tm, or the team of all worker threads. The optional character variable provides a mutex name. The optional type trace_tvariable trace_v and the optional integer variable flag provide tracing and feedback. mutex_del()The mutex_del() routine deletes a mutex synchronization object.
interface
subroutine mutex_del( m, trace_v, flag)
type( mutex_t), intent( out) :: m
type( trace_t), optional, &
intent( inout) :: trace_v
integer, optional, &
intent( out) :: flag
end subroutine mutex_del
end interface
The mutex_del() routine deletes a type mutex_t mutex variable m. The optional type trace_t variable trace_v and the optional integer variable flag provide tracing and feedback. mutex_lock()The mutex_lock() routine waits until the mutex is unlocked, and then locks the mutex.
interface
subroutine mutex_lock( m, th, &
trace_v, flag)
type( mutex_t), intent( out) :: m
type( thread_t), optional, &
intent( in) :: th
type( trace_t), optional, &
intent( inout) :: trace_v
integer, optional, &
intent( out) :: flag
end subroutine mutex_lock
end interface
The mutex_lock() routine locks a type mutex_t mutex variable m. The calling thread waits until the mutex is unlocked before locking it. If the optional type thread_t variable th is present, the thread is checked for membership in the mutex's team. The optional type trace_t variable trace_v and the optional integer variable flag provide tracing and feedback. mutex_try()The mutex_try() routine attempts to lock the mutex, and returns immediately whether locked or not.
interface
logical function mutex_try( m, th, &
trace_v, flag)
type( mutex_t), intent( out) :: m
type( thread_t), optional, &
intent( in) :: th
type( trace_t), optional, &
intent( inout) :: trace_v
integer, optional, &
intent( out) :: flag
end function mutex_try
end interface
The mutex_try() routine attempts to lock the mutex indicated by the type mutex_t mutex variable m, and returns immediately. The function returns true if the mutex is locked, and false if not. If the optional type thread_t thread variable th is present, the thread is checked for membership in the mutex's team. The optional type trace_t trace variable trace_v and the optional integer variable flag provide tracing and feedback. mutex_unlock()The mutex_unlock() routine unlocks the mutex.
interface
subroutine mutex_unlock( m, th, &
trace_v, flag)
type( mutex_t), intent( out) :: m
type( thread_t), optional, &
intent( in) :: th
type( trace_t), optional, &
intent( inout) :: trace_v
integer, optional, &
intent( out) :: flag
end subroutine mutex_unlock
end interface
The mutex_unlock() routine unlocks a type mutex_t mutex variable m. If the optional type thread_t thread variable th is present, the thread is checked for membership in the mutex's team. The optional type trace_t trace variable trace_v and the optional integer variable flag provide tracing and feedback. mutex_id()The mutex_id() return the mutex id.
interface
integer function mutex_id( m)
type( mutex_t), intent( in) :: m
end function mutex_id
end interface
The integer function mutex_id() returns the mutex id. The mutex id is a unique positive integer from one through the number of mutexs. mutex_status()The mutex_status() routine returns a mutex's statistics.
interface
subroutine mutex_status( m, name, &
locked, unlocked, &
trace_v, flag)
type( mutex_t), intent( in) :: m
character( len= *), optional, &
intent( out) :: name
integer, optional, &
intent( out) :: locked
integer, optional, &
intent( out) :: unlocked
type( trace_t), optional, &
intent( inout) :: trace_v
integer, optional, &
intent( out) :: flag
end subroutine event_status
end interface
The mutex_status() routine returns the mutex statistics of the mutex indicated by the type mutex_t mutex variable m. The optional character variable name returns the mutex's name. The optional integer variable locked returns the number of times a thread has locked the mutex. The optional integer unlocked returns the number of times a thread has unlocked the mutex. The optional type trace_t trace variable trace_v and the optional integer variable flag provide tracing and feedback. Please see our Fact Sheet, or E-mail us for more information. |
|
| Home - Fact Sheet - Free Source Code - Fortran Links - Email us |