打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
Using pthread in Android

I have a project about some system-layer in Android mainly usinglinux C programming and NDK tools.For using un-blocking socket ,I must use multi-threads but under Dalvik layerI can't use Java threadmechanism . So that I have to use pthread andusing ndk cross-complie toolchains to complie the src for myandroid phone. Fortunalety,I succeed and at least it is proved thatit's avaiable for android to use pthread.

 

The source code is too simple to pasted on ....

 

//src hello-jni.c ------------------------------------

#include <string.h>
#include <jni.h>
#include <pthread.h>

void threadmethod()
{
   printf("wtf...");
}
int main(void)
{
 //insloop();
 int ret;
 pthread_t id;
 ret=pthread_create(&id,NULL,(void*)threadmethod,NULL);
 pthread_join(id,NULL);
 printf("I am the main thread!!!");
}

 

And the Android.mk 's content is listed as below:

LOCAL_MODULE   := hello-jni
LOCAL_SRC_FILES := hello-jni.c
LOCAL_LDLIBS += -llog -lpthread

include $(BUILD_EXECUTABLE)

 

Notice the last line , I want to build a executable app not alib .

Don't forget add the pthread lib .

Then use ndk's command or script "ndk-build " to build an app,push it to your phone.

Firstly I push the file in my sdcard ,but in adb-shell when Iexec the command "chmod 777 hello-jni" it always fails .

Then I push into folder /data/data and exec the same commandsuccessfully .

I don't know why...

Then you can run your app on root authenticate.

With the Screenshot attached :

 



ps : my OS is ubuntu 10.10 withndk-r7

      my phone is htc desire Z with android 2.3.3(the kernel is2.6.35)

本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
Android NDK 实战入门指南
(转)如何在android的jni线程中实现回调
Android Studio中项目NDK原生部分整合方式 | K
NDK 开发(Android.mk配置)
呕心沥血Android studio使用JNI实例
Android Studio 4.0.+NDK .so库生成打包
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服