ThreadSafeUtils XOP

ThreadSafeUtils is an XOP adding two utility functions for threadsafe programming.

threadSafeWrapper(userFunction)

executes userFunction and returns its string if running in the main thread and an empty string otherwise. This converts the compile-time threadsafe check of Igor procedures into a runtime check.

Details

userFunction must be a function returning a string and accepting no parameters. Although allowed it does not make sense that userFunction is threadsafe, because in that case userFunction is also usable with runtime checks for thread safety.

Examples

// non threadsafe function, because GetRTStackInfo is not threadsafe
Function/S userFunction()
    return GetRTStackInfo(3)
End

// Calling workerFunction from the main thread will execute userFunction as
// expected. If called in a igor preemptive thread, treadSafeWrapper will
// not execute userFunction, instead an empty string is returned.
// Note also that workerFunction can be labelled as ThreadSafe although it
// might call the non threadsafe function userFunction.
ThreadSafe Function workerFunction()
    printf "running in main thread %d\r", runningInMainThread()
    printf "returns _%s_\r", threadSafeWrapper("userFunction")
End

Function thread()
    variable tgID = ThreadGroupCreate(4)
    ThreadStart tgID, 0, workerFunction()
   
    variable result = ThreadGroupWait(tgID, INF)
    result = ThreadGroupRelease(tgID)
End


runningInMainThread()

returns 1 if the code is executed in the Igor main thread and zero otherwise.

Project Details

Current Project Release

ThreadSafeUtils XOP IGOR.6.20.x-0.1

Release File: threadSafeUtils-0.1.zip
Version: IGOR.6.20.x-0.1
Version Date: Fri, 11/16/2012 - 11:22 am
Version Major: 0
Version Patch Level: 1
OS Compatibility: Windows
Release Notes: initial release
View All Releases

Forum

Support

Gallery

Igor Pro 8

Learn More

Igor XOP Toolkit

Learn More

Igor NIDAQ Tools MX

Learn More