创建线程时出现BSoD

发布于 2024-08-29 09:59:25 字数 1091 浏览 3 评论 0原文

我正在尝试同步创建 +5 个线程,因此不应出现任何并发错误。
代码:

System.Threading.Thread t = new System.Threading.Thread(proc);
t.Start();//==t.BlueScreen();
t.Join();

黑暗是一个特征吗?
我做错了什么吗?

操作系统:Microsoft windows vista(不幸的是)x64
语言:C# 3.0|4.0
.Net版本:3.5 | 4

编辑:

Personel[] spersonel;

过程:

void proc()
{
    spersonel = Personel.GetRows(GetThreadSafeDataConnection());
}

人员:

   internal static Personel[] GetRows(System.Data.SqlClient.SqlConnection Connection)
        {
            int i = 0;
            int c = SomeOtherGODClass.Val_int(SomeGODClass.ExecuteScalar("Select Count(*) from Personel", Connection).ToString());
            Personel[] Rs = new Personel[c];
            System.Data.SqlClient.SqlDataReader sdr = SomeGODClass.ExecuteReader("Select * from Personel", Connection);
            while (sdr.Read()) Rs[i++] = new Personel(sdr);
            sdr.Close();
            if (Rs.Length > 1) mergeSort(ref Rs);
            return Rs;
        }

I am trying to create +5 threads synchronously so there shouldn't be any concurrency error.
Code:

System.Threading.Thread t = new System.Threading.Thread(proc);
t.Start();//==t.BlueScreen();
t.Join();

Is darkness a feature ?
I am doing something wrong?

OS:Microsoft windows vista(unfortunately) x64
Language:C# 3.0|4.0
.Net version:3.5|4

edit:

Personel[] spersonel;

proc:

void proc()
{
    spersonel = Personel.GetRows(GetThreadSafeDataConnection());
}

Personel:

   internal static Personel[] GetRows(System.Data.SqlClient.SqlConnection Connection)
        {
            int i = 0;
            int c = SomeOtherGODClass.Val_int(SomeGODClass.ExecuteScalar("Select Count(*) from Personel", Connection).ToString());
            Personel[] Rs = new Personel[c];
            System.Data.SqlClient.SqlDataReader sdr = SomeGODClass.ExecuteReader("Select * from Personel", Connection);
            while (sdr.Read()) Rs[i++] = new Personel(sdr);
            sdr.Close();
            if (Rs.Length > 1) mergeSort(ref Rs);
            return Rs;
        }

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

聆听风音 2024-09-05 09:59:25

您粘贴的代码片段看起来不错,但并没有真正告诉我们太多信息。粘贴 proc 的内容会很有帮助,并为我们提供您的程序正在执行的操作的更大范围。

粘贴尽可能多的 BSoD 内容也可能会有所帮助,包括它发生的原因(访问冲突等)。虽然没有直接帮助,但可以提供一些线索。

The code snippet you pasted looks fine, but doesn't really tell us much. It would be helpful to paste contents of proc, and provide us a larger scope of what your program is doing.

It might also be helpful to paste as much of the contents of the BSoD as possible, including why it occurred (access violation, etc). Although not directly helpful, it would provide some clues.

星光不落少年眉 2024-09-05 09:59:25

您的错误代码不是典型的 BSOD 代码。它是 STATUS_PAGEFILE_QUOTA,“该进程的页面文件配额已用完。”

在 64 位版本的 Windows 上可以实现此功能。 64 位程序不会耗尽内存,它们有 16 TB 的虚拟内存。它们首先用完可映射的内存页面。操作系统对程序可以占用的页面文件大小设置了上限。你超过了。如果确实是 BSOD,那么它可能会耗尽内核内存池空间,您创建的每个线程都需要大约 24 KB 的内存用于内核堆栈。

我不得不猜测你的程序创建了太多线程。请密切关注 Taskmgr.exe 的“进程”选项卡中的“线程”列。 “性能”选项卡显示内核内存池发生的情况。

Your error code is not a typical BSOD code. It is STATUS_PAGEFILE_QUOTA, "The pagefile quota for the process has been exhausted."

Getting this on a 64-bit version of Windows is possible. 64-bit programs cannot run out of memory, they've got 16 terabytes of virtual memory. They run out of mappable memory pages first. The operating system sets an upper limit to how much of the paging file size a program can hog. You exceeded it. If it is really a BSOD then it probably ran out of kernel memory pool space, each thread you create needs about 24 KB of memory for the kernel stack.

I have to guess that your program is creating way too many threads. Keep any eye on the Threads column in Taskmgr.exe, Processes tab. The Performance tab shows what's happening to the kernel memory pool.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文