-
Notifications
You must be signed in to change notification settings - Fork 537
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
Dissable threads at compile time with NOTHREADS option #359
base: master
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The usage of the compile time flag is inconsistent. Either you use a macro to skip compiling phread_cross
and the usage of its symbols in the final library, i.e. use it as an optional library, or you use it as an alternative implementation of the pthread
functions.
The latter can further be automated by checking which system you are on. If you are on anything UNIX-like that has the pthread.h
, you use that as the native implementation of the pthread_
functions. If you are on Windows, you use our custom wrappers. Else, you use dummy noop functions that implement the interface but don't do anything.
I.e. either you do not expose the pthread
symbols or you expose them but with a noop implementation.
Also, can you rebase your PR and squash the relevant commits? The summed-up diff changes the entire thread files due to the CRLF changes from the already merged commit.
Yes, I agree the way I was treating |
I think I personally would have preferred to have a noop- How does this now deal with Also, how do you test this? Is this something that can be reproduced on the CI to make sure this compiles and does not break in the future? |
The problem with the noop- Ultimately, the issue is that we want NOTHREADS to change the meaning of We could choose to get around this by creating our own IMO the I have been testing these changes by compiling with and without the NOTHREADS cmake option, then running the simple detection code (in original PR comment) and inspecting the output of If we wanted to make automated tests for this, I think it would be sufficient to check that |
You do not need to On top of that, we can just test with macros on which platform we are on and define the types and functions appropriately. There is no need for a special flag, unless we also want to provide that non-threading option on UNIX and Windows. |
Here is my best attempt at guessing weather pthread_* types and or symbols are already defined by looking at Posix macros. Not sure if this is what you had in mind. I have left |
Pull request for #355.
My initial idea was to define empty
pthread_*
functions inpthreads_cross.{c,h}
so that when other code uses them the symbols would get resolved. Then I would enforceworker_pool->nthreads==1
so that these vacuouspthread_*
functions didnt get used.Problem is that these functions need pthread types in their signatures and we cant just typedef our own because its hard to predict if the standard libs will already define them. For example, I'm trying to cross compile to an embedded arm device for which
#import <time.h>
importssys/types.h
which importssys/pthread_types.h
which defines pthread types even thoughpthread.h
does not declarepthread_*
functions!So the way it works now is if the user defines
NOTHREADS
then all#include <pthread.h>
and all uses ofpthread
types or functions are dissabled using#ifdef
s. Then inworkerpool.c
we just ignore thenthreads
argument toworkerpool_create
.Also
workerpool.c:workerpool_get_nprocs
andcommon/pthreads_cross.c:pcthread_get_num_procs
were re-implementing the same function. So I madeworkerpool_get_nprocs
just callpcthread_get_num_procs
. IfNOTHREADS
is defined thenpcthread_get_num_procs
returns1
.I've tested this quickly by running the following code with and without NOTHREADS.
Note that these changes have been made on top of my Remove CRLF line ends commit. So diffing the branch makes it look like all the lines in
pthreads_cross.{c,h}
have changed even though only some have.