Thread Safety of Plugins

Topics about the AmiBroker platform
User avatar
Posts: 948
Joined: Thu Jul 26, 2007 7:20 pm

Thread Safety of Plugins

Postby progster » Thu Oct 18, 2012 4:47 pm

On the AB Yahoo list a user asked:

Is the Osaska 64b plugin thread safe?

TJ replied:


On single function level ALL plugins are safe, because AmiBroker implements protection internally.

The access to ALL plugins is protected internally in AmiBroker by critical section,
meaning that ALL plugin code is accessed only from ONE thread at a time.

So, as long as you are NOT using SHARED resources, you are fine.

This however, does not prevent some inter-dependencies on SHARED resources
that happen between calls.
For example:

a) formula A
Sort table X by column 1
Read table X

b) formula B
Sort the same table X by column 2
Read table X

What you are doing here is modification of shared resource.

If sorting B) is executed between sort A and read A then formula A will read table sorted
by column 2 (instead of expected column 1).

So, if you are MODIFYING tables SHARED by multiple threads, you wrap entire BLOCKS
of operations using critical section as described in the manual:

Best regards,
Tomasz Janeczko

Return to “AmiBroker Discussion”

Who is online

Users browsing this forum: No registered users and 1 guest