pthread library support on Android

9,740 views
Skip to first unread message

mak

unread,
Dec 22, 2008, 11:57:12 AM12/22/08
to android-platform
Hi All,

Is Android pthread library supports all the standard library calls ?
It is giving error while compiling code for pthread_exit( ) and
pthread_cancel( ).
Does it have some other API instead of pthread_exit( ) and
pthread_cancel( ) ?


Thanks in Advance.

Regards,
_-_Mayank Rana_-_

leemgs

unread,
Dec 22, 2008, 5:09:07 PM12/22/08
to android-...@googlegroups.com
Um.
As you know, bionic library consist of subset of glibc about pthrea api.
Below is pthread api list that I analyzed from bionic previously.


pthread_cond_signal
pthread_mutexattr_gettype
pthread_attr_destroy
pthread_attr_getstacksize
pthread_create
pthread_getspecific
pthread_attr_init
pthread_exit
pthread_attr_getstack
pthread_getcpuclockid
pthread_attr_getstackaddr
pthread_key_delete
__pthread_cleanup_pop
pthread_mutexattr_destroy
pthread_equal
pthread_attr_getguardsize
pthread_cond_timedwait_mo
pthread_detach
pthread_attr_getschedpoli
pthread_attr_setstackaddr
pthread_getschedparam
pthread_cond_broadcast
pthread_once
pthread_setschedparam
pthread_key_create
pthread_kill
pthread_cond_timeout_np
pthread_getattr_np
pthread_attr_setstacksize
pthread_sigmask
pthread_cond_init
__pthread_cleanup_push
pthread_attr_setstack
pthread_mutexattr_settype
pthread_attr_getdetachsta
pthread_mutex_unlock
pthread_self
pthread_mutexattr_init
__pthread_clone
pthread_mutex_destroy
pthread_mutex_lock
pthread_cond_wait
pthread_attr_setguardsize
pthread_mutex_trylock
pthread_cond_destroy
pthread_attr_setschedpoli
pthread_mutex_init
pthread_attr_setschedpara
pthread_attr_setdetachsta
pthread_join
pthread_cond_timedwait
pthread_attr_getschedpara
pthread_setspecific


end of line.

2008/12/23 mak <mayank....@gmail.com>:

David Turner

unread,
Dec 23, 2008, 3:48:27 AM12/23/08
to android-...@googlegroups.com
the pthread support in Bionic is restricted to the set of things we needed to get the platform running.
Except for a few exceptions, if something is not there, feel free to file a feature request or even better provide a patch for it.

NOTE: pthread_cancel() is part of the exceptions and is *not* going to be supported

David Turner

unread,
Dec 23, 2008, 3:49:02 AM12/23/08
to android-...@googlegroups.com
oh, and pthread_exit() is part of the current implementation

mak

unread,
Dec 24, 2008, 1:31:17 PM12/24/08
to android-platform
Which API can I use to replace pthread_cancel( ) functionality ?
i.e Any replacement API for pthread_cancel( ).


Regards,
_-_Mayank Rana_-_

On Dec 23, 2:49 am, "David Turner" <di...@android.com> wrote:
> oh, and pthread_exit() is part of the current implementation
>
>
>
> On Tue, Dec 23, 2008 at 9:48 AM, David Turner <di...@android.com> wrote:
> > the pthread support in Bionic is restricted to the set of things we needed
> > to get the platform running.
> > Except for a few exceptions, if something is not there, feel free to file a
> > feature request or even better provide a patch for it.
>
> > NOTE: pthread_cancel() is part of the exceptions and is *not* going to be
> > supported
>
> > On Mon, Dec 22, 2008 at 5:57 PM, mak <mayank.rana...@gmail.com> wrote:
>
> >> Hi All,
>
> >> Is Android pthread library supports all the standard library calls ?
> >> It is giving error while compiling code for pthread_exit( ) and
> >> pthread_cancel( ).
> >> Does it have some other API instead of pthread_exit( ) and
> >> pthread_cancel( ) ?
>
> >> Thanks in Advance.
>
> >> Regards,
> >> _-_Mayank Rana_-_- Hide quoted text -
>
> - Show quoted text -

David Turner

unread,
Dec 25, 2008, 4:18:14 AM12/25/08
to android-...@googlegroups.com
Try changing your code so that your threads don't get stuck waiting
indefinitely for i/o. For example used conditional variables, select
or poll to wait for events, and be sure to create a 'stop-the-thread
event'. That's how any properly written code should be anyway

Another more rustic alternative is to either close/shutdown the file
descriptor or resource the thread is waiting on, or even use
pthread-kill to send a signal to the thread, since this sill make the
system call return with EINTR (you need to unblock the signal first
though)

In all cases, be sure to properly release resources when exiting thr
thread. 99% of the code that uses pthread_cancel I have seen leaks
memory, or even locks, in certain circumstances.

Reply all
Reply to author
Forward
0 new messages