exceptions4c-pthreads 0.1
Multithreading exception handling for C
Loading...
Searching...
No Matches
exceptions4c-pthreads

Introduction

This library allows you to safely and concurrently use exceptions4c on multithreaded programs that are based on POSIX threads.

Getting Started

Adding This Extension to Your Project

This library consists of two files:

To use it in your project, include the header file in your source code files.

Thread-safe extension for exceptions4c.

And then link your program against the library code.

Important
Remember to also link your program against exceptions4c and pthreads libraries.

Usage

All you have to do is call e4c_set_context_supplier with the exception context supplier provided by this library so each thread will get its own exception context.

#include <pthread.h>
const struct e4c_exception_type OOPS = {NULL, "Oops"};
/* A Thread that throws an exception */
static void *my_thread(void *arg) {
THROW(OOPS, "Oh no");
}
int main(void) {
/* Set the thread-safe exception context supplier */
e4c_set_context_supplier(&e4c_pthreads_context_supplier);
/* Start the thread */
pthread_t thread;
pthread_create(&thread, NULL, my_thread, NULL);
pthread_join(thread, NULL);
/* The program was not terminated, only the thread was canceled */
return EXIT_SUCCESS;
}

In the event of an uncaught exception, instead of terminating the program, only the current thread will be canceled.

Note
Read the docs for more information about exceptions4c usage.

Additional Info

Compatibility

This library should compile in any modern C compiler.

Releases

This library adheres to Semantic Versioning. All notable changes for each version are documented in a change log.

Head over to GitHub for the latest release.

Latest Release

Source Code

The source code is available on GitHub.

Fork me on GitHub