Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / lazarus / 2013-05

android: debugln and thread

6 messages · 4 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Benito van der Zander

Hi,
does anyone know why creating a new thread breaks DebugLn? (till the execution returns to the JVM, Android, emulator, x86, )

This for example prints only "Started" to the log nothing else. But the thread is called and executed correctly (otherwise it would stay forever in the waiting part)

var threadActivated: boolean = false; //global variable
procedure testCalledByJVM;
begin
   DebugLn('Started');
   TTestThread.Create(false);
   DebugLn('Waiting');
   while not threadActivated do begin sleep(200); DebugLn(' .. Waiting
.. '); end;
   debugln('Done');
end;
type
  TTestThread = class(TThread)
   procedure Execute; override;
end;
  procedure TTestThread.Execute;
  begin
    debugln('THREAD TEST'); //including/excluding this line has no effect
    threadActivated:=true;
end;

Benito

Reply by email

Sven Barth
to Benito van der Zander
Benito van der Zander wrote
Hi, does anyone know why creating a new thread breaks DebugLn? (till the execution returns to the JVM, Android, emulator, x86, )

I don't know for sure what the cause could be, but: do you use FPC 2.5.1 or 2.7.1?

Regards,
Sven

Reply by email

Felipe Monteiro de Carvalho
to Sven Barth

I suppose you are talking about native code and LCL-CustomDrawn in Android, correct?

The source code for DebugLn in Android is located in lcl/interfaces/customdrawn/customdrawnobject_android.inc

procedure TCDWidgetSet.AndroidDebugLn(ASender: TObject; AStr: string;
var AHandled: Boolean;
  Target: TLazLoggerWriteTarget; Data: Pointer);
begin
  AHandled := Target in [lwtStdOut, lwtStdErr];
  if not AHandled then exit;
  __android_log_write(ANDROID_LOG_INFO, 'lclapp', PChar(AccumulatedStr+AStr));
  AccumulatedStr := '';
end;

So I suppose that FPC threading breaks __android_log_write. Try using __android_log_write directly instead of DebugLn to be 100% sure. Notice that __android_log_write is a NDK function, it is part of the Android NDK released by Google, it is not our code.

Try asking in the android-ndk Google Groups about the problem. Google engineers there helped me with problems.

One idea would be to try to see if creating a thread using pthreads directly would also break __android_log_write... I never created a thread this way, so I have no idea how to do it, but Google shows many pthreads tutorials. I suppose that Android uses pthreads, but could be wrong.

Felipe Monteiro de Carvalho

Reply by email

Benito van der Zander
to Felipe Monteiro de Carvalho
I don't know for sure what the cause could be, but: do you use FPC 2.5.1 or 2.7.1?

2.7.1

I suppose you are talking about native code and LCL-CustomDrawn in Android, correct?

mostly.
(CustomDrawn has so many bugs, so I made the GUI in java instead and call the Pascal
functions with JNI to do the calculations...)

Try using __android_log_write directly instead of DebugLn to be 100% sure.

Surprisingly that one works fine...

Benit

Felipe Monteiro de Carvalho wrote 30 lines
I suppose you are talking about native code and LCL-CustomDrawn in Android, correct? The source code for DebugLn in Android is located in lcl/interfaces/customdrawn/customdrawnobject_android.inc procedure TCDWidgetSet.AndroidDebugLn(ASender: TObject; AStr: string; var AHandled: Boolean; Target: TLazLoggerWriteTarget; Data: Pointer); begin AHandled := Target in [lwtStdOut, lwtStdErr]; if not AHandled then exit; __android_log_write(ANDROID_LOG_INFO, 'lclapp', PChar(AccumulatedStr+AStr)); AccumulatedStr := ''; end; So I suppose that FPC threading breaks __android_log_write. Try using __android_log_write directly instead of DebugLn to be 100% sure. Notice that __android_log_write is a NDK function, it is part of the Android NDK released by Google, it is not our code. Try asking in the android-ndk Google Groups about the problem. Google engineers there helped me with problems. One idea would be to try to see if creating a thread using pthreads directly would also break __android_log_write... I never created a thread this way, so I have no idea how to do it, but Google shows many pthreads tutorials. I suppose that Android uses pthreads, but could be wrong.

Reply by email

Sven Barth
to Benito van der Zander
Benito van der Zander wrote
> > I don't know for sure what the cause could be, but: do you use FPC > 2.5.1 or 2.7.1? 2.7.1

Thanks.

> Try using > __android_log_write directly instead of DebugLn to be 100% sure. Surprisingly that one works fine...

Then it is at least no problem of the android port :)

Perhaps there is some problem on the way from DebugLn to TCDWidgetSet.AndroidDebugLn...

Regards,
Sven

Reply by email

Marc Weustink
to Sven Barth
Sven Barth wrote 17 lines
On 09.05.2013 15:00, Benito van der Zander wrote: >> >> I don't know for sure what the cause could be, but: do you use FPC >> 2.5.1 or 2.7.1? > 2.7.1 Thanks. >> Try using >> __android_log_write directly instead of DebugLn to be 100% sure. > > Surprisingly that one works fine... Then it is at least no problem of the android port :) Perhaps there is some problem on the way from DebugLn to TCDWidgetSet.AndroidDebugLn...

If you don't use a widgetset, then you cannot use widgetset functions.

Marc

Reply by email