Need help with threads in Android lazarus / 43-Android ---------------------------------------------------------------------- stab · 2013-02-06 11:10 Hi all, Copied the example about synchronize from Multithreaded Application Tutorial and got it to work nicely in Windows 7. Want to use a background thread for socket communication and alert the GUI via synchronize. Made an Android app with the same code but NO LUCK. Single stepping indicated that the app is stuck at synchronize. AdbLog window shows following: I/ActivityManager( 1247): Starting: Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10200000 cmp=com.pascal.SynchronizeTest/.LCLActivity bnds=[12,115][125,273] } from pid 1430 I/ActivityManager( 1247): Start proc com.pascal.SynchronizeTest for activity com.pascal.SynchronizeTest/.LCLActivity: pid=6133 uid =10102 gids={3003, 1015} I/lclapp  ( 6133): Trying to load liblclapp.so D/dalvikvm( 6133): Trying to load lib /data/data/com.pascal.SynchronizeTest/lib/liblclapp.so 0x4051b528 D/dalvikvm( 6133): Added shared lib /data/data/com.pascal.SynchronizeTest/lib/liblclapp.so 0x4051b528 I/lclapp  ( 6133): JNI_OnLoad called I/lclapp  ( 6133): Reading our Activity Class I/lclapp  ( 6133): JNI_OnLoad finished I/lclapp  ( 6133): LCLOnCreate called by LCLActivity.onCreate I/lclapp  ( 6133): TApplication.HandleException Semaphore init failed (possibly too many concurrent threads) I/lclapp  ( 6133):   Stack trace: I/lclapp  ( 6133):   $8112CDEC I/ActivityManager( 1247): Process com.pascal.SynchronizeTest (pid 6133) has died. I/WindowManager( 1247): WIN DEATH: Window{40a0bf28 com.pascal.SynchronizeTest/com.pascal.SynchronizeTest.LCLActivity paused=false} Does someone know if it is possible to use threads in Android or am I doing something wrong in my code? Attached is my code. Regards stab ---------------------------------------------------------------------- Leledumbo · 2013-02-06 15:57 cthreads as the first unit in the .lpr? ---------------------------------------------------------------------- stab · 2013-02-06 16:09 library SynchronizeTestandroid; {$mode objfpc}{$H+} uses   customdrawnint,   Interfaces,   Forms,   customdrawn_android, customdrawndrawers, SynchronizeTestmain; Compilation error when changed to: uses   cthreads,   customdrawnint,   Interfaces,   Forms,   customdrawn_android, customdrawndrawers, SynchronizeTestmain; C:\lazarus\lazarus1.1\fpc\2.7.1\bin\i386-win32\arm-linux-ld.exe: warning: C:\Projekt\Lazarus\Android\SynchronizeTest\android\libs\armea bi\link.res contains output sections; did you forget -T? C:\lazarus\lazarus1.1\fpc\2.7.1\bin\i386-win32\arm-linux-ld.exe: cannot find -lpthread SynchronizeTestandroid.lpr(34,36) Error: Error while linking SynchronizeTestandroid.lpr(34,36) Fatal: There were 1 errors compiling module, stopping /stab ---------------------------------------------------------------------- Leledumbo · 2013-02-06 16:19 Quotecannot find -lpthreadClear enough, isn't it? Threading on *nix platforms relies on pthreads library because *nix has no native multithreading support as the case of windows. ---------------------------------------------------------------------- zariq · 2013-02-06 16:27 You don't say which compiler you are using, but there was a thread about five months ago, where it was mentioned that threads don't work in 2.5.1. I think it was Andru who mentioned he had some patches for threads in 2.6.0. By the way I usually get them errors when the paths to sdk/ndk are missing/wrong. I suppose if something wasn't implemented in the compiler you might get the same errors. ---------------------------------------------------------------------- stab · 2013-02-07 07:43 OS:          Windows 7/64bits Lazarus:  ver. 1.1 FPC:        ver. 2.7.1 SVN:        Rev. 39352MP Found pthreads in $(LazarusDir)\fpc\2.7.1\source\packages\pthreads\src\, added it to path, but get following errors when compiling: C:\lazarus\lazarus1.1\fpc\2.7.1\bin\i386-win32\arm-linux-ld.exe: warning: C:\Projekt\Lazarus\Android\SynchronizeTest\android\libs\armea bi\link.res contains output sections; did you forget -T? C:\lazarus\lazarus1.1\fpc\2.7.1\bin\i386-win32\arm-linux-ld.exe: cannot find -lpthread What does "did you forget -T" mean? Where could I find lpthread(library?)? Is it at all possible to develop for android in windows using threads or am I forced to do development in Unix? Thankful for advices? stab ---------------------------------------------------------------------- BigChimp · 2013-02-07 07:53 Quote from: stab on February 07, 2013, 08:43:18 amC:\lazarus\lazarus1.1\fpc\2.7.1\bin\i386-win32\arm-linux-ld.exe: warning: C:\Projekt\Lazarus\Android\SynchronizeTest\android\libs\armea bi\link.res contains output sections; did you forget -T? Apparently a harmless error. ---------------------------------------------------------------------- Leledumbo · 2013-02-07 13:02 QuoteFound pthreads in $(LazarusDir)\fpc\2.7.1\source\packages\pthreads\src\, added it to pathYou need the LIBRARY, not the BINDINGS. QuoteWhat does "did you forget -T" mean?http://freepascal.org/faq.var#unix-ld219 QuoteWhere could I find lpthread(library?)?In the NDK QuoteIs it at all possible to develop for android in windows using threads or am I forced to do development in Unix?Yes, you can develop from any platform as long as you know where to find required things ---------------------------------------------------------------------- stab · 2013-02-07 13:56 Leledumbo, My question:   Is it at all possible to develop for android in windows using threads or am I forced to do development in Unix? Your answer:   Yes, you can develop from any platform as long as you know where to find required things. My question and my desire was to get an advice on how to be able to use threads in android app, OK! The opinion I get from your answer is that it looks like you only want to show that you know all about this and treat those that doesn't understand as much as you as idiots. If that's all you can contribute with I'll rather be without it. /stab ---------------------------------------------------------------------- Leledumbo · 2013-02-07 14:37 QuoteThe opinion I get from your answer is that it looks like you only want to show that you know all about this and treat those that doesn't understand as much as you as idiots. If that's all you can contribute with I'll rather be without it. Seems like you misunderstood my answer then, or I misunderstood your question. You didn't ask for advice, clearly you ask for the possibility of doing the development on windows instead of unix, unless the asking-for-advice part is hidden behind your posted question. In that case, sorry, I can't read your heart nor mind, I can only read what you wrote. ---------------------------------------------------------------------- stab · 2013-02-07 15:34 Thats OK Leledumbo, but in the end of my post I wrote: Thankful for advices? ---------------------------------------------------------------------- Andru · 2013-02-07 18:02 QuoteWhere could I find lpthread(library?)?libpthread doesn't exist for Android. All pthread* functions are placed in Bionic(libc for Android). So you need to patch FreePascal, but such a patch is available here only for FreePascal from fixes_2_6 branch(revision 20768 - last not broken version). And as I remember nobody was able to build LCL with my patchset for FreePascal, and I'm not interested in investigating this, so you have no options at all until FreePascal developers provide official support for Android. ---------------------------------------------------------------------- picstart · 2013-02-07 18:17 This is a digression but from the posts I sense a frustration which I share. Things rarely work out of the box. This is not to say they always could due to different platforms and configurations. A commercial IDE has the incentive of expanding its base. Management tasks the expert coders to make it so. For Lazarus expanding the base can bring in newbies that take up the time of the unpaid experts so the incentive is diminished. Further simplification can devalue the expert's status a little. For newbies myself definitely included you get the impression everything is obtuse and worse there are several obtuse ways to proceed. Further it seems to be becoming more obtuse. Now Delphi spoiled us by providing a uniform commercial environment. Windows mostly provides a uniform environment. Lazarus and windows has some unpleasant dependencies but I always install with a clean build and it most often works. With the opportunity provided by FPC lazarus and several platforms the permutations are exponential. Unix has multiple permissions flavors of OS coupled with different processors you can almost guaranteed a single slip or omission or just different sequencing of commands and it will not work. Success is still possible; after a week of banging my head I got I2C to work from lazarus on the raspberrypi. While I did get through the forest I'm unable to vouch that I could follow my own trail since it was too obtuse with nearly a dozen OS commands and OS package installs. Instead,I take an image of the raspberrypi after things work and hope I never have to install from scratch again. Since I'm retired I can afford these almost fool's errands but for a business this would be disastrous. Lazarus is the leopard if you fall off its back it will eat you. It's an addiction; once hooked on the concept of code once run everywhere it is hard to walk away. My hope is that I will gain expertise so things become more obvious. The experts have made the Windows lazarus installs less unpleasant.Thanks. A pleasant lazarus android process would be very welcome. Thanks to the team that added a working lazarus IDE to the raspberrypi repository...it nearly gave me a heart attack when it almost worked out of the box. ---------------------------------------------------------------------- zariq · 2013-02-07 20:35 First of all apologies for continuing the digression. Yes there are frustrations, and for me personally, the most frustrating thing is that the hard work seems to have been done, but I sense the enthusiasm seems to have decreased from all sides, over the last few months. ---------------------------------------------------------------------- stab · 2013-02-08 09:00 Thank you Andru for a real answer on the topic. As I now, thanks to you, know the limitations, I think I've got an idea on how to solve my intention, even if it is through a clumpsy solution. Futhermore I'd like to say that I'm fully aware of the fact that it is volunteers that is developing FPC and Lazarus. They really do a great job which I very much appreciate. My point was only that I think if would be nice if we could reply properly like in this case Andru has done. It' was for me a negative answer but now I know the limitations and that is also a good think to know. Regards stab