问题标签 [threadcontext]

For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.

0 投票
1 回答
8019 浏览

c# - C# 中的线程上下文到底是什么?

我有一个 WCF 服务,它记录对数据库的每次调用。稍后,如果发生异常,也会将其记录到单独的数据库中。

我想要一种将这两个日志联系在一起的方法,这样我们就可以看到可能导致异常的原因。为此,我想要某种可以为每次通话获取的唯一 ID。

由于整个事情是在单个线程上执行的,例如,我可以将线程名称设置为 GUID,例如。System.Threading.Thread.CurrentThread.Name = Guid.NewGuid().ToString();但这有点hacky。

在网上搜索,我发现了,System.Threading.Thread.CurrentContext.SetProperty()但我想知道那个上下文到底是什么。它是否旨在在线程期间存储属性?每个线程是唯一的吗?

如果我有 5 个同时 WCF 调用,我不希望上下文中发生的事情之间存在任何冲突,如果它不是“每次调用”可以这么说的话。

有人可以澄清一下吗?

0 投票
3 回答
2925 浏览

python - Win 64bit GetThreadContext returns zeroe'd out registers, or 0x57 errorcode

I'm working on a Windows 7 64 bit machine (I have admin privs).

I'm using Python 2.7 (64-bit) with PyDev ctypes for Eclipse to try and read the values of registers in all threads associated with a particular PID (tried both PIDs of processes running in 64 and 32 bit modes), but when I do this, the values for the registers are all zeroe'd out. When I use Wow64GetThreadContext, the call fails with GetLastError returning 0x00000057 ('invalid parameters' according to MSDN)

I attach to the process successfully, enumerate the threads (via CreateToolhelp32Snapshot), find the threads that are owned by the process with the appropriate PID, and attempt to get the thread context. Here is my code for opening the thread and getting the thread context:

Opening a thread:

Getting context:

I call this code using:

When I run this code using GetThreadContext with the CONTEXT structure, I get the context object back for each thread, but the register values are all zero.

I have tried replacing GetThreadContext with Wow64GetThreadContext (and respectively, SuspendThread with Wow64SuspendThread), but when I do this, the call fails with error 'invalid parameters'. The arguments I give to Wow64GetThreadContext are the same as those I give to GetThreadContext, other than the name of the variables in the code I provided (this is because when I looked at their definitions in WinNT.h, they were equivalent (unless I missed something). I've defined these structures the following way:

I've done a fair amount of googling on this issue, and have tried the following to no avail:

  • According to a comment on the MSDN: CONTEXT_FULL should be CONTEXT_AMD64 | CONTEXT_CONTROL | CONTEXT_INTEGER | CONTEXT_FLOATING_POINT to be used with Win64 properly.

  • I've tried renaming the registers inside my CONTEXT and WOW_64CONTEXT structures by replacing the 'E' in the register names with 'R' (Eax -> Rax, etc.)

Has anyone else used Python with ctypes to successfully get the context of a 64-bit thread on Windows?

0 投票
1 回答
679 浏览

multithreading - 拦截方法Spring AOP的线程信息

有没有办法使用某种环绕建议来找出 AOP 拦截的方法的线程信息?例如,如果我的周围建议正在拦截登录方法,有没有办法通过 joinpointcut 等类获取实际运行登录方法的线程的信息?提前致谢。

0 投票
1 回答
1052 浏览

c - 警报处理程序中交换上下文后的分段错误

基本上我想要做的是在具有上下文切换的单个线程上模拟多线程。我每 10 微秒设置一次警报,然后将上下文从一个线程切换到另一个线程。问题是大约五分之一的运行在警报完成交换上下文后立即出现段错误,至少那是我用 gdb 跟踪它的地方。

这是我的源文件 main.c

UMT.h

和 umt.c

我尝试了很多组合并尝试通过指令进行跟踪,但无法就可能导致此段错误的原因得出结论或想法。谢谢

0 投票
1 回答
290 浏览

c++ - 教 gdb 从核心文件中理解微线程

我正在开发一个使用(定制的)微线程解决方案的大型程序。有时我需要调试崩溃。在这种情况下,能够从一个微线程切换到另一个微线程是很有用的。

如果我正在进行实时调试,我可以将所有寄存器替换为来自微线程上下文的寄存器。我写了一个宏来做到这一点,而且效果很好。

问题是,如果我正在进行事后调试(来自核心文件),我无法更改寄存器值。在这种情况下,我无法告诉 GDB 改变它对当前帧是什么的概念,因为在这种情况下所有寄存器都被认为是只读的。

有没有办法告诉 GDB 我的自定义上下文管理?

沙查尔

0 投票
2 回答
1350 浏览

c - 如何在 64 位进程(Windows)上正确保存和恢复线程上下文?

我在下面有这段代码,用于从一些 64 位进程中释放库。它完成了它的工作,但问题是在恢复保存的上下文后,目标进程就会崩溃。不知道这里有什么问题。它应该将所有寄存器和标志设置为以前的状态,对吧?我在做什么错?

0 投票
1 回答
4612 浏览

c# - 为什么选择 Thread.CurrentContext 属性和 Thread.GetDomain() 方法?

这不是一个重要的问题,但我想知道为什么 Thread 类公开了一个用于获取当前 Context ( Thread.CurrentContext ) 的属性和一个用于获取当前 AppDomain ( Thread.GetDomain() ) 的方法。

知道 Process > AppDomain > Context > Thread 的层次结构,我的假设是线程的上下文在当前时间点是已知的,并且需要根据当前上下文搜索域。

但我想听到更明智的答案。谢谢!

0 投票
1 回答
327 浏览

c# - 异步线程上下文 ID

更新现在不是问题。没有意识到 Dispatcher.Invoke 方法内外返回的 theadID 是不同的。

据我了解,当使用异步时,等待任务 T1 将在不同的线程中执行,等待之后的代码被包装为任务 T2,其 ContinueWith 为 T1。所以我假设 threadcontextID 在下面的代码中会有所不同。但是下面的代码生成相同的 ThreadContextID。我的理解错了吗?

另外,为什么我必须在 T1 中使用 Dispatcher,但可以直接在 T2 中更新主 UI?threadContext 开关在 async/await 中如何工作?谢谢。

更新: T1 中的代码正在 VS 调试线程视图的 MainThread 中执行。但是,如果是在主线程中,为什么我不能直接更新 UI?它给了我 CrossThread 异常。

UI 的 xml 代码

0 投票
2 回答
1518 浏览

c# - 我们如何为异步 .net 方法创建调用上下文?

在同步环境中,很容易创建一个作用域上下文,它允许您将带外上下文附加到当前线程。这方面的示例是当前的 TransactionScope 或线程静态日志记录上下文。

使用IDisposable 和线程静态字段的组合很容易实现上下文。

显然,这在使用异步方法时会分崩离析,因为上下文是基于线程静态字段的。所以,这失败了:

当然,我们还希望将上下文传递给调用链中的异步方法,所以这应该也可以:

有谁知道如何实施?在使用 async/await 模式时丢失带外上下文会使某些代码片段非常难看。

考虑一下您希望使用基于请求的上下文进行日志记录的异步 WebAPI 调用。您希望调用堆栈深处的记录器知道请求 ID,而无需使用参数将请求 ID 一直传递到调用堆栈。

谢谢你的帮助!

0 投票
1 回答
197 浏览

ruby-on-rails - Jruby 线程上下文实例关联

我正在尝试在 ruby​​ 中评估 javascript。

然后在我的控制器中我正在使用:

但我偶尔会收到此错误(100 个请求中有 1 个)

堆:

  • ruby 1.9 模式下的 jruby-1.7.3
  • jruby_min_runtimes & jruby_min_runtimes 为 1 的特立尼达服务器
  • 导轨 3.2.13
  • therubyrhino 2.0.2

如果我已经将最大运行时间和最小运行时间设置为 1,它不应该首先避免这个问题吗?