Re: [fpc-pascal] Java crash when fpc library CallVoidMethod in a thread.

2014-06-18 Thread fredvs
 The ideal thing would be to find some java mechanism that allows him to
`append` this checksynchronize to `the` main loop, some main-loop hook
 of sorts.

Hum, if somebody have some idea how to implement it, he is very welcome to
show his way... ;-)

PS: By the other way, here some conclusions of this topic... (if something
is wrong, please advices...)
=
http://wiki.freepascal.org/Using_Pascal_Libraries_with_Java#Dealing_with_threads_and_synchronize_Java_method_inside_threads.

Thanks.



-
Many thanks ;-)
--
View this message in context: 
http://free-pascal-general.1045716.n5.nabble.com/Java-crash-when-fpc-library-CallVoidMethod-in-a-thread-tp5719098p5719623.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] Java crash when fpc library CallVoidMethod in a thread.

2014-06-01 Thread fredvs
@ Ewald and Sven = many thanks ;-)

 The ideal thing would be to find some java mechanism that allows him to
`append` this checksynchronize to `the` main loop, some main-loop hook of
sorts.

Yep, i will be hyper-interested by that feature...

So, until that day will come, i will use a Java-timer in the main thread
(with the littlest reasonable x interval) who will call
CheckSynchronize()...

Many, many thanks for great advices...

Fred.

PS : Sorry to repeat... but fpc native libraries are much more accessible to
Java than equivalent C libraries... = mostly because of Pascal clarity and
huge help from fpc forum. Not sure that already exists C native library
accessible to Java that can do all what fpGUI or uos libraries can do...
(callback procedures, multi threads, dynamically load classical other
libraries,...).

Long life to fpc.





-
Many thanks ;-)
--
View this message in context: 
http://free-pascal-general.1045716.n5.nabble.com/Java-crash-when-fpc-library-CallVoidMethod-in-a-thread-tp5719098p5719470.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] Java crash when fpc library CallVoidMethod in a thread.

2014-05-31 Thread fredvs
 The question here is: where did you type it? 
Inside the loop in thread, after each queue()... and also just before end of
thread.

 the next thing to go for, is probably be to try to get this
`CheckSynchronize;` integrated into java in a decent manner
 (applicable to most use cases, that is). Good luck with that :-)

Yep, but using a java-timer is not the best way to use the library.
One of the great feature of uos-unit (for fpc users), is all the
queue(procedure) at begin of thread, begin/end of the loop inside the thread
and at end of the thread.
But for the uos-library I could use a java-timer who do a
fpc-checksynchronize() at x interval, but it is not perfect because it
will always loose the x interval for synchronization...

So, every idea is welcome.

Many thanks.

Fred.






-
Many thanks ;-)
--
View this message in context: 
http://free-pascal-general.1045716.n5.nabble.com/Java-crash-when-fpc-library-CallVoidMethod-in-a-thread-tp5719098p5719459.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] Java crash when fpc library CallVoidMethod in a thread.

2014-05-31 Thread Sven Barth

On 31.05.2014 12:10, fredvs wrote:

The question here is: where did you type it?

Inside the loop in thread, after each queue()... and also just before end of
thread.


*That* does not help. Queue put's the method pointer you provide into a 
queue that needs to be read by the *main thread*. It *will* fail if you 
use it from within a different thread especially the one which calls 
Queue (much worse with Synchronize, because Synchronize will *block* 
until CheckSynchronize was called).



the next thing to go for, is probably be to try to get this
`CheckSynchronize;` integrated into java in a decent manner
(applicable to most use cases, that is). Good luck with that :-)


Yep, but using a java-timer is not the best way to use the library.
One of the great feature of uos-unit (for fpc users), is all the
queue(procedure) at begin of thread, begin/end of the loop inside the thread
and at end of the thread.
But for the uos-library I could use a java-timer who do a
fpc-checksynchronize() at x interval, but it is not perfect because it
will always loose the x interval for synchronization...


There's no way around it. The only way to call CheckSynchronize is to 
call it from the main thread and that main thread is the one which 
invokes loading the library on the Java side. So the way you currently 
do it *is* the way.


Regards,
Sven

___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] Java crash when fpc library CallVoidMethod in a thread.

2014-05-31 Thread Ewald
On 05/31/2014 12:38 PM, Sven Barth wrote:
 On 31.05.2014 12:10, fredvs wrote:
 The question here is: where did you type it?
 Inside the loop in thread, after each queue()... and also just before
 end of
 thread.

 *That* does not help. Queue put's the method pointer you provide into
 a queue that needs to be read by the *main thread*. It *will* fail if
 you use it from within a different thread especially the one which
 calls Queue (much worse with Synchronize, because Synchronize will
 *block* until CheckSynchronize was called).

Couldn't have said it better ;-)


 the next thing to go for, is probably be to try to get this
 `CheckSynchronize;` integrated into java in a decent manner
 (applicable to most use cases, that is). Good luck with that :-)

 Yep, but using a java-timer is not the best way to use the library.
 One of the great feature of uos-unit (for fpc users), is all the
 queue(procedure) at begin of thread, begin/end of the loop inside the
 thread
 and at end of the thread.
 But for the uos-library I could use a java-timer who do a
 fpc-checksynchronize() at x interval, but it is not perfect because it
 will always loose the x interval for synchronization...

 There's no way around it. The only way to call CheckSynchronize is to
 call it from the main thread and that main thread is the one which
 invokes loading the library on the Java side. So the way you currently
 do it *is* the way.

Indeed, but it is not `itegrated` into the main loop (if there is one?),
the way I understand it is that he currently calls CheckSynchronize
manually. This is of course a good way to test things, and it is the way
to go if you're writing your own main loop; but I think most users don't
write their own main loop (save for embedded developers, people writing
GUI toolkits and the like).

The ideal thing would be to find some java mechanism that allows him to
`append` this checksynchronize to `the` main loop, some main-loop hook
of sorts. That is IMHO the way to go for, but as my knowledge of java is
rather limited, I cannot comment on the feasibility or practical details
of this approach.

-- 
Ewald

___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] Java crash when fpc library CallVoidMethod in a thread.

2014-05-30 Thread fredvs
@ Ewald = thanks.
Hum, i did use checksynchronize but it did not help...
Must it be used with fptimer.ontimer too ?
And why fptimer.ontimer is not executed ?
Will i have more luck with other timer like epiktimer from Graeme (or the
new one from Michael) ?
Thanks.

PS : I will try with some more checksynchronize in main thread...



-
Many thanks ;-)
--
View this message in context: 
http://free-pascal-general.1045716.n5.nabble.com/Java-crash-when-fpc-library-CallVoidMethod-in-a-thread-tp5719098p5719431.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] Java crash when fpc library CallVoidMethod in a thread.

2014-05-30 Thread Michael Van Canneyt



On Fri, 30 May 2014, fredvs wrote:


@ Ewald = thanks.
Hum, i did use checksynchronize but it did not help...


When do you call it.


Must it be used with fptimer.ontimer too ?


No.


And why fptimer.ontimer is not executed ?


If CheckSynchronize is not executed at regular intervals, 
fptimer.ontimer is not used.



Will i have more luck with other timer like epiktimer from Graeme (or the
new one from Michael) ?


AFAIK: 
Those are not the same kind of timers. They just tell you how much time passed,

they do not deliver events at specified intervals.

Michael.
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] Java crash when fpc library CallVoidMethod in a thread.

2014-05-30 Thread fredvs
re-@ Ewald :

 It *must* be called in the context of the main thread (the thread that
 loaded the library)

OOps, so do you mean that CheckSynchronize must be called by Java ?
So i have to add a custom procedure in the fpc library (who will be only a
fpc CheckSynchronize()) ?

Is it that that you mean, calling CheckSynchronize from the main Java class
(not from the main thread of the library) ?

Thanks.





-
Many thanks ;-)
--
View this message in context: 
http://free-pascal-general.1045716.n5.nabble.com/Java-crash-when-fpc-library-CallVoidMethod-in-a-thread-tp5719098p5719433.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] Java crash when fpc library CallVoidMethod in a thread.

2014-05-30 Thread Michael Van Canneyt



On Fri, 30 May 2014, fredvs wrote:


re-@ Ewald :


It *must* be called in the context of the main thread (the thread that
loaded the library)


OOps, so do you mean that CheckSynchronize must be called by Java ?
So i have to add a custom procedure in the fpc library (who will be only a
fpc CheckSynchronize()) ?

Is it that that you mean, calling CheckSynchronize from the main Java class
(not from the main thread of the library) ?


It must be called at regular intervals from the main thread of the library.
Whether this is triggered from Java, or you have some loop in your main 
thread that triggers this, is something that is in fact irrelevant for the functioning.


I don't know enough about your architecture to comment on how to do it.
I suspect though, that you will need to make it callable from Java and 
call it at regular intervals from Java code.


Michael.
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] Java crash when fpc library CallVoidMethod in a thread.

2014-05-30 Thread Ewald

On 30 May 2014, at 10:46, fredvs wrote:

 re-@ Ewald :
 
 It *must* be called in the context of the main thread (the thread that
 loaded the library)
 
 OOps, so do you mean that CheckSynchronize must be called by Java ?
 So i have to add a custom procedure in the fpc library (who will be only a
 fpc CheckSynchronize()) ?
 
 Is it that that you mean, calling CheckSynchronize from the main Java class
 (not from the main thread of the library) ?
 


Have you got an event/main loop?

If you have something like
While true do
Begin
... code ...
End;

Simply append CheckSynchronize at the end of this block:
While true do
Begin
... code ...

CheckSynchronize;
End;

If you have an eventloop, but you haven't got access to the actual code of the 
loop, you should look for mechanisms that hook up to this loop (something like 
http://wiki.freepascal.org/Main_Loop_Hooks ?); how this can be done in java, I 
do not know. You could even try using a timer to accomplish this (it is far 
from ideal, but you can experiment further then ;-) ), as long as it is a timer 
that doesn't execute it's events in it's own different thread (if applicable).

As you can see, I am rather vague on the subject, because (1) I am not a java 
programmer and (2) I don't know enough of your architecture to make any 
specific comment.

--
Ewald

___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] Java crash when fpc library CallVoidMethod in a thread.

2014-05-30 Thread fredvs
Yep, yep, yep some very good news...

1) Added a new procedure in fpc library:
 = 
procedure uos_checksynchro(PEnv: PJNIEnv; Obj: JObject) ; cdecl;
begin
checksynchronize();
end; 

2) And, of course, in fpc library exported as:
 =
exports
...
uos_checksynchro name 'Java_uos_checksynchro', 
...

3) Added in Java wrapper class:
public static native void checksynchro();

4) In main Java application:
After that the fpc thread (who does a CallVoidMethod) was called by Java
(with  uos.play(0);):

= uos.checksynchro();

5) And guess what... The CallVoidMethod is executed...

So, first conclusion : it is possible to synchronize a CallVoidMethod inside
a thread but Java main thread must call fpc-checksynchronize().

Hum, so maybe, (im new in Java) use a Java-timer who calls
uos.checksynchro(); at regular time...

1) @ Ewald = Oops i read just your answer now, i will study it...
2) @ Ewald = i prefer your solution (if i can do it work) because i prefer
not oblige Java-users to use a Java-timer.

PS : All other solutions are welcome...

PS2 : All those problems of synchronize CallVoidMethod inside a thread are
problems only for uos (audio library).
For fpGUI library, no any problems (because fpGUI library does not use
threads...), those Java developers have now the best widgetset for their
Java applications.

PS3 : Hum, if one day, i need a fptimer in a fpc library, is it possible to
use fptimer.ontimer who works with Java ?

Many thanks.

Fred.






-
Many thanks ;-)
--
View this message in context: 
http://free-pascal-general.1045716.n5.nabble.com/Java-crash-when-fpc-library-CallVoidMethod-in-a-thread-tp5719098p5719447.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] Java crash when fpc library CallVoidMethod in a thread.

2014-05-30 Thread fredvs
Please read my earlier post before this one

@ Ewald, i have try with :

 While true do
Begin
... code ...

CheckSynchronize;
End; 

But this does not work...

Thanks



-
Many thanks ;-)
--
View this message in context: 
http://free-pascal-general.1045716.n5.nabble.com/Java-crash-when-fpc-library-CallVoidMethod-in-a-thread-tp5719098p5719448.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] Java crash when fpc library CallVoidMethod in a thread.

2014-05-30 Thread Ewald
On 05/30/2014 01:15 PM, fredvs wrote:
 Please read my earlier post before this one

 @ Ewald, i have try with :

  While true do
 Begin
 ... code ...

 CheckSynchronize;
 End; 

 But this does not work...

The question here is: where did you type it?

Anyway, as you've already gotten it to work, there is no need to try
this; the next thing to go for, is probably be to try to get this
`CheckSynchronize;` integrated into java in a decent manner (applicable
to most use cases, that is). Good luck with that :-)

-- 

Ewald

___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] Java crash when fpc library CallVoidMethod in a thread.

2014-05-30 Thread Sven Barth
Am 30.05.2014 13:09 schrieb fredvs fi...@hotmail.com:
 Hum, so maybe, (im new in Java) use a Java-timer who calls
 uos.checksynchro(); at regular time...

If the timer event runs in the same thread as your current call to
checksynchro resides then it will work. If it's executed by a different
thread then not.

 PS3 : Hum, if one day, i need a fptimer in a fpc library, is it possible
to
 use fptimer.ontimer who works with Java ?

With your current usage of checksynchro fptimer.OnTimer should work as well
(you can't currently use it without a CheckSynchronize though).

Regards,
Sven
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

Re: [fpc-pascal] Java crash when fpc library CallVoidMethod in a thread.

2014-05-29 Thread fredvs
Hello Sven, hello Michael = many tanks.

I have follow your advices... but...

I have then create a object and a procedure inside that object.
I use then queue() or synchronize()  inside the thread to execute that
procedure of object.
That procedure call CallvoidMethod.
OK, everything compiles but when queue() or synchronize() inside the thread
is called, now, ok, no crash but CallvoidMethod is not executed...
I have try also to use a fptimer(nil) (outside the thread) that uses, for
ontimer, a procedure that call CallvoidMethod but, same as queue() or
synchronize() inside the thread, no crash but the timer does not execute
CallvoidMethod at fptimer.ontimer...

PS : Im sure that CallvoidMethod is working and use the right parameters (if
a call CallvoidMethod outside the thread, directly (not via
fptimer.ontimer), the java method is executed..

@ Michael = of course, im hyper interested by your code

Many thanks.

Fred




-
Many thanks ;-)
--
View this message in context: 
http://free-pascal-general.1045716.n5.nabble.com/Java-crash-when-fpc-library-CallVoidMethod-in-a-thread-tp5719098p5719429.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] Java crash when fpc library CallVoidMethod in a thread.

2014-05-29 Thread Ewald
On 05/29/2014 11:18 AM, fredvs wrote:
  but the timer does not execute
 CallvoidMethod at fptimer.ontimer...
Just a guess here...

To quote Sven a few mails ago: `CheckSynchronize is used to process
calls to TThread.Synchronize and TThread.Queue. It *must* be called in
the context of the main thread (the thread that loaded the library).
TFPTimer uses Synchronize internally, [...]`

But you didn't use the word `CheckSynchronize` anywhere in your mail.
You need to call this method regularly in you main thread, if you don't
call it, nothing will happen; you only fill up the queue that
CheckSynchronize is supposed to empty. See
http://www.freepascal.org/docs-html/rtl/classes/checksynchronize.html
for more details on this call.

-- 
Ewald

___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

Re: [fpc-pascal] Java crash when fpc library CallVoidMethod in a thread.

2014-05-28 Thread Michael Schnell

On 05/26/2014 09:47 PM, fredvs wrote:

Hum, checksynchronize(), i do not realy understand how to use in the
thread/loop...


I am working on an ActiveNoUIi widget type to be usable with Lazarus. 
Here you can use normal Lazarus compatible TTimers.


This already works nicely for me (Linux X86 32 Bit).

The code is some 500 lines.

If you want to test it I can send it to you.

-Michael
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] Java crash when fpc library CallVoidMethod in a thread.

2014-05-26 Thread fredvs
Hello.
What is the best way to  unthread a procedure ?
I have try with a fptimer outside the thread but the thing that disturb me
is that you need a tcomponent as owner to create it.
And in the library i do not use any tcomponent...
How to create a fptimer without owner ?
I have try with fptimer.create(Nil) but without luck...
Thanks

PS: if you have a better idea how to unthread, im verry interessed



-
Many thanks ;-)
--
View this message in context: 
http://free-pascal-general.1045716.n5.nabble.com/Java-crash-when-fpc-library-CallVoidMethod-in-a-thread-tp5719098p5719400.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] Java crash when fpc library CallVoidMethod in a thread.

2014-05-26 Thread Michael Van Canneyt



On Mon, 26 May 2014, fredvs wrote:


Hello.
What is the best way to  unthread a procedure ?
I have try with a fptimer outside the thread but the thing that disturb me
is that you need a tcomponent as owner to create it.
And in the library i do not use any tcomponent...
How to create a fptimer without owner ?
I have try with fptimer.create(Nil) but without luck...


A fptimer.create(nil) should always work. 
fptimer does not need a non-nil owner.


But if you don't have components, you probably also don't have a main 
application loop.
So I think it likely that then you probably also do not call checksynchronize() at 
regular intervals, meaning that fptimer will not work, as this is required to get the ticks.


So, the Nil owner is (with 99.99% certainty) not the problem.

Michael.
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] Java crash when fpc library CallVoidMethod in a thread.

2014-05-26 Thread fredvs
Yep, Michael, thanks...
Ok then for Nil owner...
Hum, checksynchronize(), i do not realy understand how to use in the
thread/loop...
In the loop i do not use synchronize, because the procedure that is called
is a java/method  and synchronize is for procedure of object outside the
thread... (Or i miss something ).
Ps : this is the very last obstacle for total intégration into java (thread
are working perfect, only calling java/method iniside the thread is
problematic...)
Ps2 : maybe i have to forget to use thread inside a library (but if it is
possible then: whow...)




-
Many thanks ;-)
--
View this message in context: 
http://free-pascal-general.1045716.n5.nabble.com/Java-crash-when-fpc-library-CallVoidMethod-in-a-thread-tp5719098p5719402.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] Java crash when fpc library CallVoidMethod in a thread.

2014-05-26 Thread Sven Barth

On 26.05.2014 21:47, fredvs wrote:

Yep, Michael, thanks...
Ok then for Nil owner...
Hum, checksynchronize(), i do not realy understand how to use in the
thread/loop...
In the loop i do not use synchronize, because the procedure that is called
is a java/method  and synchronize is for procedure of object outside the
thread... (Or i miss something ).


CheckSynchronize is used to process calls to TThread.Synchronize and 
TThread.Queue. It *must* be called in the context of the main thread 
(the thread that loaded the library). TFPTimer uses Synchronize 
internally, because it uses a thread to keep track of the timing and 
notifies the main thread using Synchronize. Maybe one could add a 
non-synchronize mode, then oneself would need to make sure that eventual 
accesses inside the event handler are synchronized (CritialSections, 
etc.) correctly.


Regards,
Sven

___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] Java crash when fpc library CallVoidMethod in a thread.

2014-05-03 Thread fredvs
 Did you use AttachCurrentThread and DetachCurrentThread?

Oops, what is that ? How must i use it ?

 Pay attention to the validity of local references as well as their
 number. 

Idem, what is local references as well as their number. ?

PS: Im a beginner with Java but, apart CallVoidMethod in threads, everything
is working as i want.

Many thanks.





-
Many thanks ;-)
--
View this message in context: 
http://free-pascal-general.1045716.n5.nabble.com/Java-crash-when-fpc-library-CallVoidMethod-in-a-thread-tp5719098p5719118.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] Java crash when fpc library CallVoidMethod in a thread.

2014-05-03 Thread fredvs
 Posting some code might help. 

I may post code but not sure it will help.
The code is the same as
http://wiki.freepascal.org/Using_Pascal_Libraries_with_Java, section dealing
with callback procedure ( but inside a thread).

Hum, i would prefer some demo-working-code from somebody who knows how to do
it...

Many thanks.



-
Many thanks ;-)
--
View this message in context: 
http://free-pascal-general.1045716.n5.nabble.com/Java-crash-when-fpc-library-CallVoidMethod-in-a-thread-tp5719098p5719119.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] Java crash when fpc library CallVoidMethod in a thread.

2014-05-02 Thread Michael Van Canneyt



On Thu, 1 May 2014, fredvs wrote:


Hello.

When a java class use a fpc library that call jni.CallVoidMethod inside a
thread it crash the application.

If the fpc library call jni.CallVoidMethod  directly (not via a thread) =
perfect, it works.

Is that a known problem ?


Not known, but definitely expected.

FPC has it's specific threading mechanism in the RTL. 
Java has such a mechanism in place as well.


I would be very surprised if the 2 could cooperate without a lot of additional 
glue code.

In general, libraries and threading is not an easy story.

Michael.
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] Java crash when fpc library CallVoidMethod in a thread.

2014-05-02 Thread fredvs
 In general, libraries and threading is not an easy story. 

Ok,..., but what is your advice to do a  CallVoidMethod inside a thread ?

PS: Everything, inside the thread is working perfectly, only CallVoidMethod
does crash...

Do you think i could have better result with a kind of post-messages ?

Many thanks.

Fred



-
Many thanks ;-)
--
View this message in context: 
http://free-pascal-general.1045716.n5.nabble.com/Java-crash-when-fpc-library-CallVoidMethod-in-a-thread-tp5719098p5719113.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] Java crash when fpc library CallVoidMethod in a thread.

2014-05-02 Thread patspiper

On 02/05/14 02:22, fredvs wrote:

Hello.

When a java class use a fpc library that call jni.CallVoidMethod inside a
thread it crash the application.

If the fpc library call jni.CallVoidMethod  directly (not via a thread) =
perfect, it works.

Is that a known problem ?

Maybe does it exist something else than jni.CallVoidMethod for inside a
thread (like synchronize or queue for procedure of object) ?

Here the java error message :

# A fatal error has been detected by the Java Runtime Environment:
#
#  SIGSEGV (0xb) at pc=0x7f6d0e405be1, pid=5145, tid=140105962755840
#
# JRE version: OpenJDK Runtime Environment (7.0_51) (build 1.7.0_51-b00)
# Java VM: OpenJDK 64-Bit Server VM (24.45-b08 mixed mode linux-amd64
compressed oops)
# Problematic frame:
# V  [libjvm.so+0x4debe1]
Exceptions::throw_stack_overflow_exception(Thread*, char const*, int,
methodHandle)+0x211
#
# Failed to write core dump. Core dumps have been disabled. To enable core
dumping, try ulimit -c unlimited before starting Java again


Did you use AttachCurrentThread and DetachCurrentThread?

Pay attention to the validity of local references as well as their number.

Posting some code might help.

Stephano
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] Java crash when fpc library CallVoidMethod in a thread.

2014-05-02 Thread Michael Van Canneyt



On Fri, 2 May 2014, patspiper wrote:


dumping, try ulimit -c unlimited before starting Java again


Did you use AttachCurrentThread and DetachCurrentThread?


That is probably the additional glue code I was talking about in my reply.

Michael.
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal