Re: [fpc-pascal] Call function in shared library from multiple threads
>> TDummyThread.Create(True) > Huh, I have memory leak with this. > Should it not be: --> TDummyThread.Create(false) ? (because with this, no > memory leak) Hello. Sorry to come back with this but without answer I am still full of doubt. Is TDummyThread.Create(True) wanted and so the dummy thread must exist during all the application and freed at end of application ? Or is TDummyThread.Create(false) ok ? Thanks. Fre;D - Many thanks ;-) -- View this message in context: http://free-pascal-general.1045716.n5.nabble.com/Call-function-in-shared-library-from-multiple-threads-tp5728035p5728202.html Sent from the Free Pascal - General mailing list archive at Nabble.com. ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Call function in shared library from multiple threads
> TDummyThread.Create(True) Huh, I have memory leak with this. Should it not be: --> TDummyThread.Create(false) ? (because with this, no memory leak) Fre;D - Many thanks ;-) -- View this message in context: http://free-pascal-general.1045716.n5.nabble.com/Call-function-in-shared-library-from-multiple-threads-tp5728035p5728091.html Sent from the Free Pascal - General mailing list archive at Nabble.com. ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Call function in shared library from multiple threads
On Fri, Mar 31, 2017 at 1:15 PM, Henry Vermaakwrote: > On Fri, Mar 31, 2017 at 08:42:24AM -0700, fredvs wrote: > > > Z:\home\fred\uos\examples\uos.pas(7438,29) Warning: (4046) > Constructing a > > > class "TThread" with abstract method "Execute" > > > > Huh, is it Is it serious doctor? > > I use this: > > function DummyThread(param: pointer): ptrint; > begin > Result := 0; > EndThread(Result); > end; > > begin > BeginThread(@DummyThread); > ... > ... > end. What about calling TM directly? Something like this: uses cthreads; var TM: TThreadManager; begin TM := Default(TThreadManager); // just hiding hint 'variable TM doesn't seem to be initialized' GetThreadManager(TM); IsMultiThread := TM.InitManager; ... end. I can't test it now (I would like to debug it asap), but I think FPC offer some option to start the TM without starting a new -- dummy -- thread. o.O -- Silvio Clécio ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Call function in shared library from multiple threads
Michael Van Canneyt wrote > Best is probably: > > Type >TDummyThread = Class(TThread) >public > procedure execute; override; >end; > > procedure TDummyThread.Execute; > > begin >FreeOnTerminate:=True; >Terminate; > end; > > > begin >TDummyThread.Create(True) > end. OK, perfect, no more warning, thanks doctor. Fre;D - Many thanks ;-) -- View this message in context: http://free-pascal-general.1045716.n5.nabble.com/Call-function-in-shared-library-from-multiple-threads-tp5728035p5728060.html Sent from the Free Pascal - General mailing list archive at Nabble.com. ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Call function in shared library from multiple threads
On Fri, Mar 31, 2017 at 08:42:24AM -0700, fredvs wrote: > > Z:\home\fred\uos\examples\uos.pas(7438,29) Warning: (4046) Constructing a > > class "TThread" with abstract method "Execute" > > Huh, is it Is it serious doctor? I use this: function DummyThread(param: pointer): ptrint; begin Result := 0; EndThread(Result); end; begin BeginThread(@DummyThread); ... ... end. ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Call function in shared library from multiple threads
On Fri, 31 Mar 2017, fredvs wrote: Hello. Michael Van Canneyt wrote To fix that, you can do the following. In the library startup code, create a dummy thread. This will initialize the threads mechanism: with TThread.Create(False) do end. I use this for initialize my libraries: Best is probably: Type TDummyThread = Class(TThread) public procedure execute; override; end; procedure TDummyThread.Execute; begin FreeOnTerminate:=True; Terminate; end; begin TDummyThread.Create(True) end. Michael. ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Call function in shared library from multiple threads
Hello. Michael Van Canneyt wrote > To fix that, you can do the following. > In the library startup code, create a dummy thread. > This will initialize the threads mechanism: > >with TThread.Create(False) do > > end. I use this for initialize my libraries: With TThread.Create(False) do Terminate; It works ok but there is that warning after compiling: > Z:\home\fred\uos\examples\uos.pas(7438,29) Warning: (4046) Constructing a > class "TThread" with abstract method "Execute" Huh, is it Is it serious doctor? Fre;D - Many thanks ;-) -- View this message in context: http://free-pascal-general.1045716.n5.nabble.com/Call-function-in-shared-library-from-multiple-threads-tp5728035p5728057.html Sent from the Free Pascal - General mailing list archive at Nabble.com. ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Call function in shared library from multiple threads
Thanks a lot! Seems to working fine now ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Call function in shared library from multiple threads
On Thu, 30 Mar 2017, Michael Van Canneyt wrote: On Thu, 30 Mar 2017, Krzysztof wrote: 2017-03-30 15:19 GMT+02:00 Michael Van CanneytNevertheless, that should work. I've used it in multi-threaded apache modules. Well it doesn't work or fpjson module is not thread safe in this case. You can test it by yourself with attached demo (first post). Try it few times because sometimes if you are lucky then there is no error If I find a moment, I will test. I can reproduce the problem. At least partially it is related to the threads mechanism not being initialized correctly. To fix that, you can do the following. In the library startup code, create a dummy thread. This will initialize the threads mechanism: library testlib; {$mode objfpc}{$H+} uses cthreads, cmem, Classes, testlibu; exports InitTest, FinalizeTest, Test; begin with TThread.Create(False) do end. After this, I no longer get the problem (which doesn't mean there are no other possible problems :) ) Michael. ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Call function in shared library from multiple threads
On Thu, 30 Mar 2017, Krzysztof wrote: 2017-03-30 15:19 GMT+02:00 Michael Van CanneytNevertheless, that should work. I've used it in multi-threaded apache modules. Well it doesn't work or fpjson module is not thread safe in this case. You can test it by yourself with attached demo (first post). Try it few times because sometimes if you are lucky then there is no error If I find a moment, I will test. Michael. ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Call function in shared library from multiple threads
2017-03-30 15:19 GMT+02:00 Michael Van Canneyt> > > Nevertheless, that should work. > > I've used it in multi-threaded apache modules. > Well it doesn't work or fpjson module is not thread safe in this case. You can test it by yourself with attached demo (first post). Try it few times because sometimes if you are lucky then there is no error ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Call function in shared library from multiple threads
On Thu, 30 Mar 2017, Michael Van Canneyt wrote: On Thu, 30 Mar 2017, Krzysztof wrote: Yes, I'm aware of cthreads and tested it too (without it also critical sections don't work) but it doesn't help with attached examples. Still same errors in logs Nevertheless, that should work. I should add that WITHOUT using cthreads, it certainly will NOT work. Michael. ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Call function in shared library from multiple threads
On Thu, 30 Mar 2017, Krzysztof wrote: Yes, I'm aware of cthreads and tested it too (without it also critical sections don't work) but it doesn't help with attached examples. Still same errors in logs Nevertheless, that should work. I've used it in multi-threaded apache modules. Michael. ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Call function in shared library from multiple threads
Yes, I'm aware of cthreads and tested it too (without it also critical sections don't work) but it doesn't help with attached examples. Still same errors in logs ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal