Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

opaque handles can be fully defined in thpool.h #65

Closed
wants to merge 7 commits into from
Closed

opaque handles can be fully defined in thpool.h #65

wants to merge 7 commits into from

Conversation

jti-lanl
Copy link

This resolves #64, using the "alternative" approach, allowing construction of libraries that contain files that use a threadpool.

jti-lanl and others added 7 commits December 1, 2017 09:49
This resolves [issue 64 of the original
repo](#64), using the
"alternative" approach, allowing construction of libraries that contain
files that use a threadpool.

This still allows compiler type-checking of API arguments, passing of
pointer-sized values (actual pointers, I'd assume, from a reasonable
compiler), and protects the threadpool "handle" from mucking about by
applications.
One case where our application wanted to violate the "opaque handles" of
the previous commit, was to associate a pthread_t with the internal index
in the array of threadpool threads.  This is useful to allow an application
to have its own arrays of data that have per-thread elements.  However, We
don't want to provide an extension to the API that allows callers to see
the pthread_t values in its internal arrays.

To address this, `thpool_thread_index()` requires the caller to provide a
pthread_t, and returns the corresponding index.  Thus, we don't expose any
thread-handles to the caller that they don't already have.

Also, in the previous commit thpool_init() was still returning NULL instead
of the new opaque handles, in the case of errors.  It now returns a handle
containing a NULL pointer.  All existing apps that test the return value
will have to be changed.  We provide `thpool_null()` for this.  Such apps
should now use something like this:

   if (thpool_null(threadpool))
      // thpool_init() failed ...
CMakeLists.txt update to add compile flags and require pthread
This pull request was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

incomplete definition of type 'struct thpool_'
2 participants