5.8 Summary

The basic usage of Contexts is as follows:

  1. Call fz_new_context to create a context. Pass in any custom allocators required. If you wish to use MuPDF from multiple threads at the same time, you must also pass in locking functions. Set the store size appropriately.
  2. Call fz_clone_context to clone the context as many times as you need; typically once for each ‘worker’ thread.
  3. Perform the operations required using MuPDF within fz_try/fz_catch constructs.
  4. Call fz_drop_context with each cloned context.
  5. Call fz_drop_context with the original context.

Things to remember:

  1. A fz_context can only be used in 1 thread at a time.
  2. A fz_document can only be used in 1 thread at a time.
  3. A fz_device can only be used in 1 thread at a time.
  4. A fz_context shares the store with all the fz_contexts cloned from it.