[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: libssh multi-threading issue
[Thread Prev] | [Thread Next]
- Subject: Re: libssh multi-threading issue
- From: Anne Zhang <meantobe997@xxxxxxxxxxx>
- Reply-to: libssh@xxxxxxxxxx
- Date: Mon, 28 Apr 2014 12:15:50 -0700
- To: libssh@xxxxxxxxxx
Hi, I have the implementation of pthread.c for windows platform but not sure how to get the library build. Is there any cmake changes that needs to get the threading library build for windows like libssh_thread.so in Linux? Thanks, Anne On Thu, Apr 17, 2014 at 1:56 PM, Aris Adamantiadis <aris@xxxxxxxxxxxx>wrote: > Hi Anne, > > Sorry nobody in libssh team is experienced in windows programming. The > concept is exactly the same, however there is no equivalent to > libssh-pthreads, you will have to implement the threading callbacks by > yourself. Feel free to take inspiration from > http://git.libssh.org/projects/libssh.git/tree/src/threads/pthread.c > I'm sure the windows code will be very similar. > > Aris > > Le 17/04/14 22:45, Anne Zhang a écrit : > > Any tips on how to get this working on windows? It will be very helpful. > > > > Thanks, > > > > Anne > > > > > > On Wed, Apr 16, 2014 at 6:58 PM, Anne Zhang <meantobe997@xxxxxxxxxxx > > <mailto:meantobe997@xxxxxxxxxxx>> wrote: > > > > Hi Aris, > > > > Thanks so much for the reply. It works in my Linux environment! I > > tried: > > > > static int initialized=0; > > static pthread_mutex_t mutex1 = PTHREAD_MUTEX_INITIALIZER; > > pthread_mutex_lock(&mutex1); > > if (!initialized){ > > ssh_threads_set_callbacks(ssh_threads_get_pthread()); > > ssh_init(); > > initialized = 1; > > } > > pthread_mutex_unlock( &mutex1 ); > > > > So is there a similar mechanism in Windows? I noticed there is a > > libssh_threads.so in libssh for linux but not for window. > > > > What do I pass in ssh_threads_set_callbacks() for windows? Is > > there anything i should notice for the build of libssh under windows? > > > > > > On Wed, Apr 16, 2014 at 11:43 AM, Dustin Oprea > > <myselfasunder@xxxxxxxxx <mailto:myselfasunder@xxxxxxxxx>> wrote: > > > > On Wed, Apr 16, 2014 at 2:26 PM, Aris Adamantiadis > > <aris@xxxxxxxxxxxx <mailto:aris@xxxxxxxxxxxx>> wrote: > > > > Hi Anne, > > > > There's an easy solution: before every ssh_connect, put an > > initialization procedure protected by a mutex. This is not > > optimal > > (because every new connection will have to lock+unlock a > > mutex) but you > > are guaranteed that ssh_init gets called only once. > > > > > > I like it. That's a cute solution for her requirements, Aris. > > > > > > > > Dustin > > > > > > Pseudocode: > > > > do_my_connect(){ > > static int initialized=0; > > static mutex init_mutex; > > > > mutex_lock(&init_mutex); > > if (!initialized){ > > initialize_threading(); > > initialized = 1; > > } > > mutex_unlock(&init_mutex); > > > > > > Regards, > > > > Aris > > > > Le 16/04/14 17:53, Anne Zhang a écrit : > > > Hi Mike, > > > > > > Thanks for the reply. Unfortunately, I am only > > implementing an .so > > > file and have no access to the main program. I > > understand ssh_init() > > > would solve the problem but my library is being called > > within a thread > > > and I cannot change what's in the main/original thread. > > > > > > Look forward to additional input. > > > > > > Thanks, > > > > > > Anne > > > > > > > > > On Wed, Apr 16, 2014 at 2:53 AM, Mike Jones > > <mrjones@xxxxxxxxxx <mailto:mrjones@xxxxxxxxxx> > > > <mailto:mrjones@xxxxxxxxxx <mailto:mrjones@xxxxxxxxxx>>> > > wrote: > > > > > > On 4/16/2014 1:51 AM, ZhangAnne wrote: > > >> Hi, > > >> > > >> I am implementing a shared library, and met the > > threading issue > > >> when the program calls my library and executes > > multiple threads > > >> in parallel. Since my lib is being called by other > > program, I > > >> cannot initialize the threading outside of any > > threading context > > >> as mentioned > > >> here: > > http://api.libssh.org/master/libssh_tutor_threads.html > > >> > > >> My control to the code is limited within the scope > > of my library. > > >> I am wondering if there is any workaround other > > than changing > > >> code ouside my library? > > >> > > >> Thanks, > > >> > > >> Anne > > > > > > If it helps, I used libssh in a multi-threaded > > application without > > > calling ssh_threads_set_callbacks() or linking > > libssh_threads. > > > In fact, I never even read this part of the libssh > > documentation > > > before today. :) > > > > > > The main/original thread of the application calls > > ssh_init() and > > > then spawns off one additional thread that makes all > > the other > > > libssh calls. > > > The freeing of resources and ssh_finalize() are done > > back in the > > > original thread after this other thread has finished. > > > > > > So far there have been no issues that I can > > attribute to using it > > > this way. > > > > > > We're running on Linux (RedHat 6.x) and using > > libpthread. > > > > > > - Mike > > > > > > > > > > > > > > > > > > > > > > > > >
libssh multi-threading issue | ZhangAnne <meantobe997@xxxxxxxxxxx> |
Re: libssh multi-threading issue | Mike Jones <mrjones@xxxxxxxxxx> |
Re: libssh multi-threading issue | Anne Zhang <meantobe997@xxxxxxxxxxx> |
Re: libssh multi-threading issue | Aris Adamantiadis <aris@xxxxxxxxxxxx> |
Re: libssh multi-threading issue | Dustin Oprea <myselfasunder@xxxxxxxxx> |
Re: libssh multi-threading issue | Anne Zhang <meantobe997@xxxxxxxxxxx> |
Re: libssh multi-threading issue | Anne Zhang <meantobe997@xxxxxxxxxxx> |
Re: libssh multi-threading issue | Aris Adamantiadis <aris@xxxxxxxxxxxx> |