diff options
author | Nicolas Viennot <nicolas@viennot.biz> | 2013-06-10 00:58:12 -0400 |
---|---|---|
committer | Nicolas Viennot <nicolas@viennot.biz> | 2013-06-10 02:50:07 -0400 |
commit | 0f7ccda4fb34685d5bbd62eba3ff8d5f63bdc71b (patch) | |
tree | 5cbf451994ed987cf4b37fab2f130c5e4ab19b7e /libssh/doc/threading.dox | |
parent | 220b2afb3c4596b875624a5024fff134234cb102 (diff) |
Adding libssh
Diffstat (limited to 'libssh/doc/threading.dox')
-rw-r--r-- | libssh/doc/threading.dox | 65 |
1 files changed, 65 insertions, 0 deletions
diff --git a/libssh/doc/threading.dox b/libssh/doc/threading.dox new file mode 100644 index 00000000..a11c82f7 --- /dev/null +++ b/libssh/doc/threading.dox @@ -0,0 +1,65 @@ +/** +@page libssh_tutor_threads Chapter 8: Threads with libssh +@section threads_with_libssh How to use libssh with threads + +libssh may be used in multithreaded applications, but under several conditions : + - Threading must be initialized during the initialization of libssh. This + initialization must be done outside of any threading context. + - If pthreads is being used by your application (or your framework's backend), + you must link with libssh_threads dynamic library and initialize + threading with the ssh_threads_pthreads threading object. + - If an other threading library is being used by your application, you must + implement all the methods of the ssh_threads_callbacks_struct structure + and initialize libssh with it. + - At all times, you may use different sessions inside threads, make parallel + connections, read/write on different sessions and so on. You *cannot* use a + single session (or channels for a single session) in several threads at the same + time. This will most likely lead to internal state corruption. This limitation is + being worked out and will maybe disappear later. + +@subsection threads_init Initialization of threads + +To initialize threading, you must first select the threading model you want to +use, using ssh_threads_set_callbacks(), then call ssh_init(). + +@code +#include <libssh/callbacks.h> +... +ssh_threads_set_callbacks(ssh_threads_get_noop()); +ssh_init(); +@endcode + +ssh_threads_noop is the threading structure that does nothing. It's the +threading callbacks being used by default when you're not using threading. + +@subsection threads_pthread Using libpthread with libssh + +If your application is using libpthread, you may simply use the libpthread +threading backend: + +@code +#include <libssh/callbacks.h> +... +ssh_threads_set_callbacks(ssh_threads_get_pthread()); +ssh_init(); +@endcode + +However, you must be sure to link with the library ssh_threads. If +you're using gcc, you must use the commandline +@code +gcc -o output input.c -lssh -lssh_threads +@endcode + + +@subsection threads_other Using another threading library + +You must find your way in the ssh_threads_callbacks_struct structure. You must +implement the following methods : +- mutex_lock +- mutex_unlock +- mutex_init +- mutex_destroy +- thread_id + +Good luck ! +*/ |