- mongodb - 在 MongoDB mapreduce 中,如何展平值对象?
- javascript - 对象传播与 Object.assign
- html - 输入类型 ="submit"Vs 按钮标签它们可以互换吗?
- sql - 使用 MongoDB 而不是 MS SQL Server 的优缺点
我正在将中型 C++ 代码体移植到 Android NDK。不幸的是,pthreads 实现(无论如何,从 NDK v5 开始)是不完整的。具体来说,我们的应用程序依赖 pthread_cancel() 来终止工作线程。 NDK 没有实现 pthread_cancel()!当工作线程正常响应时,还有其他明显的答案。但是在工作线程没有响应的情况下(例如无限循环),我怎样才能在不杀死整个进程的情况下取消它?
最佳答案
适用于此人的可能选项:http://igourd.blogspot.com/2009/05/work-around-on-pthreadcancel-for.html
在此转发以防万一:
Then I use pthread_kill to trigger a SIG_USR1 signal and use signal handler to exit this pthread and tried it, it works, but still wondering if any drawbacks for this kind of method.
超时:
if ( (status = pthread_kill(pthread_id, SIGUSR1)) != 0)
{
printf("Error cancelling thread %d, error = %d (%s)", pthread_id, status, strerror status));
}
USR1 处理程序:
struct sigaction actions;
memset(&actions, 0, sizeof(actions));
sigemptyset(&actions.sa_mask);
actions.sa_flags = 0;
actions.sa_handler = thread_exit_handler;
rc = sigaction(SIGUSR1,&actions,NULL);
void thread_exit_handler(int sig)
{
printf("this signal is %d \n", sig);
pthread_exit(0);
}
看起来最好的答案是重写,这样线程就不会在 IO 上等待:http://groups.google.com/group/android-platform/browse_thread/thread/0aad393da2da65b1
关于c++ - Android NDK 中的 pthread_cancel() 替代方案?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4610086/
我正在使用 ndk r9b 版本在 android 中构建 ffmpeg 2.1.3。 我使用了下面的命令。 ./configure --enable-shared --prefix=/home/fb
c 函数 pthread_cancel() 可以阻塞还是总是立即返回?我的手册页指出: The above steps happen asynchronously with respect to th
您好,我有一个关于取消使用互斥锁和条件变量的线程的问题。该线程已延迟取消类型。当我只使用函数pthread_mutex_lock/unlock 和pthread_cond_wait 时,一个取消请求到
我正在阅读 Kerrisk's book并看到以下内容作为注释, Caution is required when using a cast integer as the return value o
这个问题已经有答案了: pthread_cancel() function failed to terminate a thread (2 个回答) 已关闭 8 年前。 我在主线程中创建并连接了 2
我开发了一个程序,它在开始时创建一个线程。然后我想在线程运行时使用 pthread_cancel() 终止线程。 但是如果我这样做,我就会崩溃。这种崩溃并不总是能够重现。有时程序会避免崩溃。 我发现如
当我的进程执行完毕时,我想使用 pthread_cancel 取消我的“计时器”线程。基本上我们正在将一个修改后的终端作为一个项目进行。当我在一个终端中调用 sleep 300 时,我希望能够打开另一
关闭。此题需要details or clarity 。目前不接受答案。 想要改进这个问题吗?通过 editing this post 添加详细信息并澄清问题. 已关闭 3 年前。 Improve th
我正在用我的 C 测试代码测试 pthread_cancel() 功能。这不是我正在使用的确切代码,而是用于解释的简化形式。 int main(argc, char *argvp[]) { w
我有一个程序试图通过已实现的池使用创建和取消。 创建如下: int threadsNum=10; while (createdid = created; st->t = newThread;
我有一个程序试图通过已实现的池使用创建和取消。 创建如下: while (createdid = created; st->t = &newThread; pthread_mutex_
在我的程序中,我有两个线程,一个计算一些递归函数,另一个在第一个线程进行计算时显示“进度点”。有代码: #include #include #include #include #include
我的问题类似于this one .但是看完它的所有答案,我仍然不知道pthread_cancel()能得到什么样的安全保证。所以我想问一个更具体的问题: 假设 pthread_cancel() 是在一
我正在使用 pthread_create() 和 pthread_cancel() 函数来创建多线程程序,但我注意到 pthread_cancel() 确实没有真正终止它应该终止的线程。 void c
我正在学习 pthread_cancel 函数并测试线程是否会在未达到取消点时被取消。线程由默认属性创建,并使其在添加循环中运行。但是当发送取消请求并且线程立即退出时。它没有达到取消点,我认为它不应该
大家好,我有一些关于线程的问题,例如我有一些线程 1 分配了一些内存,另一个线程(假设 2)是使用 pthread_cancel() 或仅使用 return 杀死线程 1 它分配的内存和平发生了什么?
我使用的 pthread 不分配任何局部变量。由于我不会在这里讨论的原因,我需要一个 pthread_cancel() 选项,并且我正在编写的线程应该能够支持它(没有资源需要清理,可以在以下位置停止执
我正在尝试从主线程中取消一个线程。它不会立即取消,但大约需要 4 秒。应该是因为我已将其取消类型设置为与默认(延迟)异步。为什么? #include #include #include #inc
我现在正在维护一些代码,它使用 pthread_create() 创建一个 pthread。此线程还在创建后不久调用 pthread_detach(pthread_self());。此外,它使用 pt
我有一个程序应该启动一个线程。为了避免退出软件,线程在无限循环中运行,我加入了线程。这个线程永远不应该返回一个值。所以现在我有一个问题,在我调用 pthread_cancel valgrind 后检测
我是一名优秀的程序员,十分优秀!