Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

HPS API can be accessible from multiple threads. If you plan on using multiple threads, please keep the following in mind:
1. Avoid calling .Type() function:

For example:

Code Block
// DO NOT USE Type()
HPS::Key generic_key;
if (generic_key.Type() == HPS::Type::LineKey)
{
    HPS::LineKey line_key = (HPS::LineKey) generic_key;
    // do stuff with the LineKey
}

Type() is expensive and will slowdown performance. Type() has to synchronize the database in order to know the true type of the Key. When you call Type(), all database operations are paused until the internal task queue is emptied. Only after the task queue is emptied can HPS determine the precise type of the Key and report that back to the user.

...

Code Block
For example, do this:
HPS::Key generic_key;
try {
    HPS::LineKey line_key(generic_key);
    // do stuff with the LineKey
}
catch (...)
{
    // generic_key didn't exist, or wasn't actually a line. 
}

2. Deleting Keys

You may need to pay special attention if you are deleting any Keys. If you delete a Key, the next time it's used (perhaps in a different thread), it will throw an exception. If there are multiple threads in play, you will need to add exception handling for deleted Keys.

3. Kits are not thread-safe

One thing that is NOT thread-safe is Kits. If you're passing or sharing kits across threads, you will need to synchronize them on your endcheck out our forum post for more information.