Frameworks
Integrations
Mendix
SharePoint
Modular UI
Legacy UI
AnnotationManager
Annotation Types
Customize
Version 11
Version 10
v10.12
v10.11
v10.10
v10.9
v10.8
v10.7
v10.6
v10.5
v10.4
v10.3
v10.2
v10.1
v10.0
Version 8
v8.12
v8.11
v8.10
v8.9
v8.8
v8.7
v8.6
v8.5
v8.4
v8.3
v8.2
v8.1
v8.0
Version 7
Version 6
v6.3
v6.2
v6.1
v6.0
Version 5
Version 4
Version 3
Version 2
WebViewer Server
WebViewer BIM
If you plan on sharing a single PDF document instance across multiple threads, then you need to lock the document. Not locking a PDF document instance shared across threads can result in undefined behaviour, including crashing.
An Apryse SDK lock is based on two principles:
Reentrant mutex (also known as recursive lock)
Recursive mutex may be locked multiple times by the same process/thread without causing a deadlock.
Readers-writer (RW) lock (also known as shared-exclusive lock)
An RW lock allows concurrent access for read-only operations, while write operations require exclusive access.
To write to a PDF document in a multithreaded environment.
Only one thread can hold a write lock at any given time.
Multithreaded PDF reading
Full source code which illustrates how to use PDFDoc locking mechanisms to access the document concurrently. PDFDoc uses a recursive shared lock model.
To read and write to a PDF document in a multithreaded environment.
A thread cannot acquire a write lock while holding a read lock.
Multithreaded PDF reading
Full source code which illustrates how to use PDFDoc locking mechanisms to access the document concurrently. PDFDoc uses a recursive shared lock model.
As computing devices become more parallel in nature, Apryse is evolving to allow developers to leverage this power in new and exciting ways. Apryse version 6.0 introduces new locking semantics which allow for concurrent access of a PDFDoc
instance. This was done to improve performance during interactive viewing (simultaneous rendering, text extraction, etc.), as well as to open up the possibility for new use cases (parallel rendering). This article introduces the locking system, and will get you on your way to developing parallel applications with Apryse SDK.
Apryse uses a recursive read/write locking system. Multiple threads can hold a read lock on the document, but only one thread can hold a write lock at any given time. A thread can acquire an equivalent or weaker lock as many times as it likes without causing a deadlock. In other words, the following is valid:
However, a thread cannot acquire a write lock while holding a read lock. Because one can only acquire a write lock when no read locks are held, this situation would inevitably lead to a deadlock. To avoid this scenario, Apryse will throw a runtime exception whenever the situation occurs.
Some of our API calls internally acquire a write lock on the document. As a result, these calls can also throw a runtime exception if they are invoked while holding a read lock. This is noted in each method's documentation. Additionally, you will find a complete list of those methods at the end of this article.
In general, the parts of our library that manage the UI will maintain document locks. For the lower level calls which actually modify the document, you are responsible for maintaining document locks.
Apryse provides the following APIs for locking the document:
The new locking system is backwards compatible, meaning previous calls to PDFDoc.Lock
now acquire a write lock. If you would like to take advantage of the ability to read a PDF concurrently, it is your responsibility to review document locks and determine whether it is safe to downgrade them to a read lock.
Conversely, if you are happy with the existing 'one document, one thread' model previously used in Apryse 5.9., you can continue to work with this system. No change is required on your behalf.
Did you find this helpful?
Trial setup questions?
Ask experts on DiscordNeed other help?
Contact SupportPricing or product questions?
Contact Sales