Hello all,
Hello All,
Do we care about no pthreads support at compile time?
I would prefer to suppose that we always HAVE_PTHREADS.
That would make the code much more readable. I dream of removing
all the #ifdef HAVE_PTHREADS in the code, and suppose
that we do have Pthreads at compile time. I cannot name a
Linux distribution not having pthreads. Today, every libc ships
with them.
It is 2018. Onion is mostly POSIX targetted. Do we still care
today about POSIX systems without pthreads support? Even cheap
computers have threads, and most of them have two cores at least
(ok cheap Rasperry Pi Zero W are single core, but a Linux kernel
on them could run a few threads). My feeling is that people coding
for these ultracheap devices either will use a Linux kernel
capable of multithreading, or install some IoT micro OS like
Contiki -on which onion cannot run-.
Of course, we still have a mode where people won't use O_THREADED
at onion_new time. But that happens at runtime.
BTW; I think that most public routines in onion.c should
systematically use
#ifdef HAVE_PTHREADS
pthread_mutex_lock(&server->mutex);
#endif /*HAVE_PTHREADS*/
near their beginning
and the corresponding
#ifdef HAVE_PTHREADS
pthread_mutex_unlock(&server->mutex);
#endif /*HAVE_PTHREADS*/
near their end.
David and all, I believe that all public functions in onion.h
should be thread-friendly (since they could be called by some
application thread, outside of the event loop thread), unless explicitly
documented as thread-unsafe (this is not the case in latest commit
99fd33d5825666df9).
So they need both calls to pthread_mutex_lock & pthread_mutex_unlock.
If there are not thread-friendly, we should document that
explicitly (in a doxygen-ed comment) and perhaps adopt some naming
convention (maybe a suffix like _noth). I just committed
src/onion/onion.c
in my onion, commit d17c05ce4708278
but this is untested code (I just have added
systematically these pthread_mutex_lock & pthread_mutex_unlock
like above). I just checked that it compiles. Could you please
tell me if I am on the right track? What public functions
from onion.h do you expect to be callable after the
event loop (so after start of onion_listen)? What public
functions on onion* do you expect to be called from
other threads (application-specific ones).
Perhaps some functions in onion.h are supposed to be callable
inside requests processing. Then we probably need the mutex to be
recursive (and that makes it slower). Otherwise, we need to
document which onion.h functions cannot be called by request
processing. What did you decide?
In other words, do we want an application accept some POST request to do some onion_set_max_threads ? I guess that not, but then we should document that. Otherwise, the mutex needs to be recursive (so a bit slower).
BTW, in my scenario (bismon)
almost all HTTP requests are actually processed elsewhere than in
Onion-related threads. The basic scenario is : add some "agenda
task" to be processed by some existing thread pool (outside of
onion) and wait till that thread pool is pthread_cond_notify-ing
that my view of the HTTP exchange has completed. Then the onion
thread is sending the response back (to the browser).
Regards.
-- Basile STARYNKEVITCH == http://starynkevitch.net/Basile opinions are mine only - les opinions sont seulement miennes Bourg La Reine, France
David and all, I believe that all public functions in onion.h should be thread-friendly (since they could be called by some application thread, outside of the event loop thread), unless explicitly documented as thread-unsafe (this is not the case in latest commit 99fd33d5825666df9). So they need both calls to pthread_mutex_lock & pthread_mutex_unlock. If there are not thread-friendly, we should document that explicitly (in a doxygen-ed comment) and perhaps adopt some naming convention (maybe a suffix like _noth). I just committed src/onion/onion.c in my onion, commit d17c05ce4708278 but this is untested code (I just have added systematically these pthread_mutex_lock & pthread_mutex_unlock like above). I just checked that it compiles. Could you please tell me if I am on the right track? What public functions from onion.h do you expect to be callable after the event loop (so after start of onion_listen)? What public functions on onion* do you expect to be called from other threads (application-specific ones).
The HAVE_PTHREADS removal mostly will improve readability.