About threads in a service process

by rktb » Sat, 14 Mar 2009 05:01:19 GMT


Sponsored Links
 i,

- What do the methods startThreadPool() and joinThreadPool() do during
the process of launching a service, e.g., mediaplayer service in the
file main_mediaserver.cpp?
int main(int argc, char** argv)
{
sp<ProcessState> proc(ProcessState::self());
sp<IServiceManager> sm = defaultServiceManager();
LOGI("ServiceManager: %p", sm.get());
AudioFlinger::instantiate();
MediaPlayerService::instantiate();
CameraService::instantiate();
ProcessState::self()->startThreadPool();
IPCThreadState::self()->joinThreadPool();
}

- I have a service that I am using and see multiple threads on the
server side. Below is a snippet of the log.
03-13 19:52:58.143 26 45 V IMyTest: BnMyTest::onTrasact ...
tid=45
03-13 19:52:58.143 26 44 V IMyTest: BnMyTest::onTrasact ...
tid=44
03-13 19:52:58.183 26 26 V IMyTest: BnMyTest::onTrasact ...
tid=26
03-13 19:52:58.213 26 45 V IMyTest: BnMyTest::onTrasact ...
tid=45
03-13 19:52:58.213 26 44 V IMyTest: BnMyTest::onTrasact ...
tid=44
03-13 19:52:58.233 26 45 V IMyTest: BnMyTest::onTrasact ...
tid=45
03-13 19:52:58.233 26 26 V IMyTest: BnMyTest::onTrasact ...
tid=26
03-13 19:52:58.233 26 184 V IMyTest: BnMyTest::onTrasact ...
tid=184

If I read this correctly, the service is running on a process with
pid=26. But, the "onTransact" calls happen on multiple threads. I did
verify that the "Transact" calls occur in all one thread (on the
application process). Though there appear to be multiple threads (ids)
running, it looks like the calls are serialized. How come there are
multiple threads? Is there a way to control the number of threads
running on the server process?


Thanks,
Ravi


On Feb 12, 3:13pm, rktb <yend...@pv.com> wrote:
--~--~---------~--~----~------------~-------~--~----~



About threads in a service process

by Freepine » Sat, 14 Mar 2009 08:50:13 GMT


 tartThreadPool() will spawn a new thread into the thread pool which talks
with binder driver, while joinThreadPool() will put the calling thread
itself into thread pool.

It seems there is no API to control the maximum number of binder threads in
the pool, and sometimes driver will tell the process to spawn new thread
automatically via BR_SPAWN_LOOPER command.

On Sat, Mar 14, 2009 at 1:01 PM, rktb <yend...@pv.com> wrote:


--~--~---------~--~----~------------~-------~--~----~


Sponsored Links


About threads in a service process

by rktb » Sat, 14 Mar 2009 13:34:40 GMT


 ut, these threads don't run concurrently...right? I am trying to
understand what kind of precautions the native library needs to take
in the case of multiple threads.

-Ravi

On Mar 14, 3:49am, Freepine <freep...@gmail.com> wrote:
--~--~---------~--~----~------------~-------~--~----~



About threads in a service process

by Dianne Hackborn » Sun, 15 Mar 2009 02:17:21 GMT


 es they run concurrently, that is why they are separate threads. :)

Currently the maximum number of threads in a process's thread pool is 16.

On Sat, Mar 14, 2009 at 6:34 AM, rktb <yend...@pv.com> wrote:



--
Dianne Hackborn
Android framework engineer
hack...@android.com

Note: please don't send private questions to me, as I don't have time to
provide private support. All such questions should be posted on public
forums, where I and others can see and answer them.

--~--~---------~--~----~------------~-------~--~----~



About threads in a service process

by rktb » Sun, 15 Mar 2009 03:05:32 GMT


 ianne's earlier response on binders and services:
http://groups.google.com/group/android-developers/msg/d76e607aa62c1cad



On Mar 14, 9:17pm, Dianne Hackborn <hack...@android.com> wrote:
--~--~---------~--~----~------------~-------~--~----~



About threads in a service process

by rktb » Sun, 15 Mar 2009 03:09:43 GMT


 hanks Dianne.

I think I am missing something very basic here. Please help me out.
The way I understand it, atleast through the logs, all IPC calls
across the binder are synchronous, i.e., Transact and corresponding
OnTransact calls are serialized. Then, how could the threads run
concurrently? Is this the case when two applications are accessing the
same service?

-Ravi

On Mar 14, 9:17pm, Dianne Hackborn <hack...@android.com> wrote:
--~--~---------~--~----~------------~-------~--~----~



About threads in a service process

by rktb » Sun, 15 Mar 2009 04:10:49 GMT


 nother article about threads and binders:
http://www.angryredplanet.com/~hackbod/openbinder/docs/html/BinderThreading.html

On Mar 14, 10:09pm, rktb <yend...@pv.com> wrote:
--~--~---------~--~----~------------~-------~--~----~



About threads in a service process

by Dave Sparks » Mon, 16 Mar 2009 17:04:37 GMT


 nless otherwise specified, all binder calls are synchronous to the
calling process (usually referred to as the client process). They are
completely asynchronous to the callee (usually referred to as the
server process).

What this means is that the caller will block in the binder call until
the server thread has completed the requested action. On the server
side, the binder request is picked up by on the worker threads, it
proceeds serially until the work is complete, and then returns the
result to the caller across the binder. It is possible for multiple
worker threads to be concurrent within the server process acting on
behalf of different clients, and perhaps even different threads of the
same client.

On Mar 14, 8:09 pm, rktb <yend...@pv.com> wrote:
--~--~---------~--~----~------------~-------~--~----~



About threads in a service process

by rktb » Mon, 16 Mar 2009 21:15:36 GMT


 hanks Dave.

On Mar 16, 12:04pm, Dave Sparks <davidspa...@android.com> wrote:
--~--~---------~--~----~------------~-------~--~----~



Other Threads

1. shootme FC mulu nih

ada alternatif gak ya...nyari drocap di market ga nemu sih....

rgds

-- 
"Indonesian Android Community [id-android]" 

2. Root itu apa dan perlu ngak? Baca disini:

http://www.androidcentral.com/forward?path=node/8683

Regards,

Daniel Tumiwa

sent from the TumiwaDroid Nexus One

-- 
"Indonesian Android Community [id-android]" 

3. apk: doodledroid *enwan ready*

4. apk: midomi

5. what is pending intent?

6. online jobs

7. Kapasitas memry htc g1