标签: suspend

Windows SuspendThread 没有?(GetThreadContext 失败)

我们有一个 Windows32 应用程序,其中一个线程可以通过执行 SuspendThread/GetThreadContext/ResumeThread 来停止另一个线程以检查其状态 [PC 等]。

if (SuspendThread((HANDLE)hComputeThread[threadId])<0)  // freeze thread
   ThreadOperationFault("SuspendThread","InterruptGranule");
CONTEXT Context, *pContext;
Context.ContextFlags = (CONTEXT_INTEGER | CONTEXT_CONTROL);
if (!GetThreadContext((HANDLE)hComputeThread[threadId],&Context))
   ThreadOperationFault("GetThreadContext","InterruptGranule");
Run Code Online (Sandbox Code Playgroud)

极少数情况下,在多核系统上,GetThreadContext 返回错误代码 5(Windows 系统错误代码“拒绝访问”)。

SuspendThread 文档似乎清楚地表明目标线程已挂起,如果没有返回错误。我们正在检查 SuspendThread 和 ResumeThread 的返回状态;他们从来没有抱怨过。

怎么可能我可以挂起一个线程,但不能访问它的上下文?

这个博客 http://www.dcl.hpi.uni-potsdam.de/research/WRK/2009/01/what-does-suspendthread-really-do/

表明 SuspendThread 在返回时可能已开始暂停另一个线程,但该线程尚未暂停。在这种情况下,我可以看出 GetThreadContext 会有什么问题,但这似乎是定义 SuspendThread 的愚蠢方法。(SuspendThread 的调用如何知道目标线程何时真正挂起?)

编辑:我撒谎了。我说这是针对 Windows 的。

好吧,奇怪的事实是,我在 Windows XP 64 下没有看到这种行为(至少在上周没有,我真的不知道在那之前发生了什么)……但我们一直在测试这个 Windows 应用程序Ubuntu 10.x 上的 Wine。当由于某种原因尝试获取线程状态失败时,GetThreadContextWine 源在第 819 行包含拒绝访问的返回响应。我在猜测,但似乎 Wine GetThreadStatus 认为线程可能无法重复访问。为什么在 SuspendThead 超出我的范围之后这会是真的,但有代码。想法?

EDIT2:我又撒谎了。我说我们只看到了 Wine 上的行为。不......我们现在发现了一个 Vista …

windows winapi multithreading suspend

5
推荐指数
1
解决办法
8265
查看次数

如何在没有过时的Thread.Suspend的情况下暂停阻塞线程?

我有一个在等待一个线程TcpListener.AcceptTcpClient(),该,我想在次暂停.

我已经读过Monitor.Wait(...),但我只有使用互斥锁的经验,如果线程等待阻塞方法,它会变得有趣.

现在Thread.Suspend(...)已经过时了,我应该如何暂停线程?

c# multithreading suspend

5
推荐指数
1
解决办法
503
查看次数

sigsuspend() 不对信号作出反应

我的目标是相互通信主要进程及其“叉”子进程。通信是通过信号传递完成的。

当第一个孩子在等待 SIGUSR1 信号时卡住等待时,我的问题就出现了。

我不知道为什么它会卡在这一点上。甚至,如果我通过控制台发送信号,该子进程似乎没有注意到。

有人可以帮我吗?


代码来了

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <signal.h>

int N = 5;
int _pipe[2];
pid_t children[5];

void main(){
    pid_t parent_pid;
    pid_t pid;
    int i = 0;

    sigset_t set;
    sigfillset(&set);

    parent_pid = getpid();
    fprintf(stderr,"I am main process, here comes my pid %u\n",getpid());

    if (0>pipe(_pipe)) fprintf(stderr,"Error when creating pipe");

    //Start creating child processes
    while (i < N){
            pid = fork();
            if (pid == 0){
                close(_pipe[1]);
            break;
        }
        else{
            fprintf(stderr,"Created child with pid %u\n",pid);
            children[i] = …
Run Code Online (Sandbox Code Playgroud)

c posix fork signals suspend

5
推荐指数
1
解决办法
1478
查看次数

如何在 Android 设备上启用挂起到磁盘?

众所周知,Linux 内核支持待机、挂起到内存、挂起到磁盘。然而,我发现Android不支持suspend-to-diskhibernate,尽管它的内核源自Linux。
现在,我想在 Android 上启用它,但不知道如何操作。我将基于Andorid 4.1Linux 3.0.8来完成我的工作。
您愿意提供任何有用的信息吗?以前有人这样做过吗?谢谢。

android hibernate suspend

5
推荐指数
1
解决办法
4461
查看次数

Windows Phone 8.1应用程序在恢复期间崩溃(可能是因为它在暂停期间挂起)

我有一种情况,我的应用程序有时会在暂停/恢复过程中崩溃.场景如下所示:

  1. 应用程序正常运行.
  2. 用户通过点击开始按钮,使用文件选择器或启动另一个应用程序等操作退出应用程序.此时,执行应用程序挂起事件处理程序.根据我生成的所有调查和日志,我知道挂起事件处理程序执行时没有错误.延迟对象(暂停过程的一部分)被标记为完成.通常,挂起过程需要200-500毫秒.
  3. 在短暂的间隔后,用户返回到应用程序.
  4. 操作系统显示"正在恢复..."消息几秒钟.
  5. Once in a while (it is rather hard to repro) the "Resuming…" message disappears and the OS start screen is shown – indicative of the fact that the app crashed. According to all the investigation and logs I produce I know that the resuming event handler is not called.
  6. When the app crashes the OS creates an application dump file.

Taking the app dump file and examining it using WinDBG shows a call stack like …

c# crash suspend crash-dumps windows-phone-8.1

5
推荐指数
0
解决办法
411
查看次数

Kotlin 挂起函数递归调用

突然发现 suspend 函数的递归调用比调用同一个函数但没有suspend修饰符要花费更多的时间,所以请考虑下面的代码片段(基本的斐波那契数列计算):

suspend fun asyncFibonacci(n: Int): Long = when {
    n <= -2 -> asyncFibonacci(n + 2) - asyncFibonacci(n + 1)
    n == -1 -> 1
    n == 0 -> 0
    n == 1 -> 1
    n >= 2 -> asyncFibonacci(n - 1) + asyncFibonacci(n - 2)
    else -> throw IllegalArgumentException()
}
Run Code Online (Sandbox Code Playgroud)

如果我调用此函数并使用以下代码测量其执行时间:

fun main(args: Array<String>) {
    val totalElapsedTime = measureTimeMillis {
        val nFibonacci = 40

        val deferredFirstResult: Deferred<Long> = async {
            asyncProfile("fibonacci") { asyncFibonacci(nFibonacci) } as …
Run Code Online (Sandbox Code Playgroud)

recursion asynchronous suspend kotlin kotlin-coroutines

5
推荐指数
1
解决办法
2122
查看次数

Kotlin foreach 在地图上与与协程一起使用时迭代键

我对以下代码发生的事情感到困惑。task.yield 是一个从 a 到 b 的哈希映射,而 store.put 是一个挂起函数,它接受一个 a 和一个 b。第一种遍历地图的方法没有问题,第二种方法也是如此。第三种方式对我来说是最自然的迭代方式,也是我最初编写的方式,导致 kotlin 抱怨挂起函数只能在协程主体内调用。我猜这与地图上的 forEaching 如何工作有关(可能与列表相反?)但我真的不明白问题是什么。

launch{
    // Kotlin is perfectly happy with this
    for(elt in task.yield.keys){
        store.put(elt,task.yield[elt]!!)
    }
    // and this
    task.yield.keys.forEach { 
        store.put(it,task.yield[it]!!)
    }
    // This makes kotlin sad. I'm not sure why
    task.yield.forEach { t, u ->
        store.put(t, u)
    }
}
Run Code Online (Sandbox Code Playgroud)

编辑:我刚刚注意到 forEach 列表是一个内联函数,而我尝试使用的地图不是。我猜是这个问题。

suspend kotlin kotlinx.coroutines

5
推荐指数
1
解决办法
3410
查看次数

此 UWP 进程已暂停以提高系统性能...但它不是 UWP 应用

我们有一个基于 .NET Framework 4.8 构建的 WPF 应用程序,但最近我们在任务栏中看到了这个(在 Windows 10 x64 上运行):

任务栏

将鼠标悬停在 WPF 客户端上时,工具提示显示“此 UWP 进程已暂停,以提高系统性能”。我们的应用程序在再次执行一些工作之前也挂起了一段时间。这怎么可能?我们不是在 .NET Core 3.0 上运行,没有桌面桥,根本没有 UWP 集成......这只是一个普通的 WPF 应用程序。

wpf suspend windows-10 uwp

5
推荐指数
0
解决办法
2708
查看次数

Android 插桩测试在测试使用 RoomDatabase.withTransaction 的挂起函数时会冻结

我正在尝试测试以下 LocalDataSource 函数NameLocalData.methodThatFreezes函数,但它冻结了。我该如何解决这个问题?或者我如何以另一种方式测试它?

要测试的类

class NameLocalData(private val roomDatabase: RoomDatabase) : NameLocalDataSource {

  override suspend fun methodThatFreezes(someParameter: Something): Something {
    roomDatabase.withTransaction {
      try {
        // calling room DAO methods here
      } catch(e: SQLiteConstraintException) {
        // ...
      }
      return something
    }
  }
}
Run Code Online (Sandbox Code Playgroud)

测试班

@MediumTest
@RunWith(AndroidJUnit4::class)
class NameLocalDataTest {
  private lateinit var nameLocalData: NameLocalData

  // creates a Room database in memory
  @get:Rule
  var roomDatabaseRule = RoomDatabaseRule()

  @get:Rule
  var instantTaskExecutorRule = InstantTaskExecutorRule()

  @Before
  fun setup() = runBlockingTest {
     initializesSomeData()
     nameLocalData = …
Run Code Online (Sandbox Code Playgroud)

testing android suspend android-room

5
推荐指数
1
解决办法
338
查看次数

Arrow 挂起函数和 monad 理解之间的关系

我是《绿箭侠》的新手,并尝试建立其效果系统如何工作的思维模型;特别是它如何利用 Kotlin 的suspend系统。我非常模糊的理解如下;如果有人可以确认、澄清或纠正它,那就太好了:

由于 Kotlin 不支持更高种类的类型,因此将应用程序和 monad 实现为类型类非常麻烦。相反,Arrow 从 Kotlin 的挂起机制提供的延续原语中派生出所有 Arrow 的单子类型的单子功能(绑定和返回)。这是正确的吗?特别是,短路行为(例如, fornullableeither)以某种方式实现为定界延续。我不太明白 Kotlin 挂起机制的哪个特定功能在这里发挥作用。

如果上述内容大致正确,那么我有两个后续问题:我应该如何包含非 IO 单子操作的范围?举一个简单的对象构造和验证示例:

suspend fun mkMessage(msgType: String, appRef: String, pId: String): Message? = nullable {
    val type = MessageType.mkMessageType(msgType).bind()
    val ref = ApplRefe.mkAppRef((appRef)).bind()
    val id = Id.mkId(pId).bind()
    Message(type, ref, id)
}
Run Code Online (Sandbox Code Playgroud)

在 Haskell 的 do 表示法中,这将是

mkMessage :: String -> String -> String -> Maybe Message
mkMessage msgType appRef pId = do
    type <- mkMessageType msgType
    ref <- …
Run Code Online (Sandbox Code Playgroud)

suspend kotlin arrow-kt

5
推荐指数
1
解决办法
1025
查看次数