2

Here is a pretty serious crisis I am facing. I am having an application which was designed for windows and windows thread is used in my code.

This is the scenerio I want to port my application to android and I know windows thread doesn't run on Android os. Can any body tell me how can I change my threading to support Android.

Yes rewriting threads in P-threads is good option but is there any easy way to support multithreading on Android with existing windows thread.

Threading on both Windows and Linux

I referred the above link where it tells about threading in Linux and windows using boost::thread.

But the problem is the lib is in C++ and my code is in C

Looking forward for your input for easy transition of windows thread to threading for my android app.

Thanks in Advance

Community
  • 1
  • 1
Harrisson
  • 255
  • 2
  • 21
  • 3
    You know, that Android code is written in Java, right? – flx Feb 22 '14 at 11:15
  • 4
    Thanks for the reply. Yes, I do know that Android code can be written in Java. However, my application code is in C language and intel x86. – Harrisson Feb 22 '14 at 11:35
  • 3
    @Harrisson, I've heard tell of a Native Development Kit for Android that gives you C/C++... https://developer.android.com/tools/sdk/ndk/index.html – bazza Feb 23 '14 at 07:43
  • 3
    @bazza, I actually have the NDK. I think my question is not clear. Here is the scenario, I have a application which was previously designed for desktop and it has some intel intrinsics and earlier we had used windows thread. I am new to pthreads and android as well. Now, I want to port the windows thread from my previous application to pthread so that it can run on Android. – Harrisson Feb 23 '14 at 08:58
  • @Harrison, well, a thread in Windows isn't so very different from a thread in Linux. Pthread_create() will give you a thread that will behave in the same way as a Windows thread. Process priority is handled quite differently by the OSes, but I doubt that that will affect your app. The Win32 API is very different to POSIX, so I think the biggest job you'll have is translating between the two. The Intel intrinsics, what they're doing? If memory fences then maybe semaphores haven't been used. Worth programming them in. SSE? You'll need a library or you'll need to read a lot of books on ARM. – bazza Feb 25 '14 at 05:59

1 Answers1

1

The threading by itself should not be an issue, write your own CreateThread method that creates a pthread and that's it. The concern will be with thread synchronization, if your code heavily uses Mutexes, Events, Semaphores and/or wait for thread termination, porting them to pthread might not be straigtforward, indeed the worst will be the WaitForMultipleObjects which is tricky to re-write.

Nicolas Defranoux
  • 2,646
  • 1
  • 10
  • 13