阻塞的线程很多时为何会发生死锁?急!(我是新用户,只有给50分的权利,Sorry!)

yehong 2000-03-02 10:32:00
在驱动程序中,有一段处理硬盘I/O的非共享程序(较长,执行时间
大约在10到500ms,在该段程序的开端采用了互斥,一般情况下工作
正常。但在频繁的硬盘读写期间(例如,在Windows98里拷贝大量文件),
鼠标响应会越来越慢,直至完全停止响应。估计是由于阻塞的线程太多
造成系统死锁。为什么会这样呢?还是有其他原因?应如何解决此问题,
还盼高手们帮帮我!急!急!!
...全文
242 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
yehong 2000-03-03
  • 打赏
  • 举报
回复
哦,对了,谢谢netmare,这里本是mov eax, 0
deepwater 2000-03-02
  • 打赏
  • 举报
回复
Increase your buffer fo reading/writing,thus decrease the times of reading/writing hard disk.

In my last project,I used the two methods
deepwater 2000-03-02
  • 打赏
  • 举报
回复
I once had the same experiance
I guess if u run your progamm on NT it will be OK,your trouble on 95/98 attributes to the implmentation of 95/98 's multithread - If one thread of a process is reading/writing hard disk,the other processes or threads will not get CPU time unless the reading/writing is finished.
One solution which I took : Sleep for 100~200 ms in your thread which reads or writes hard disk

Tell me your result please
blaise 2000-03-02
  • 打赏
  • 举报
回复
post your code
netmare 2000-03-02
  • 打赏
  • 举报
回复
xor eax, eax
jz lGWH_ret ;it's reenter, return to calldown
这不对吧,这等于jmp lGWH_ret
yehong 2000-03-02
  • 打赏
  • 举报
回复
致blaise:
这是出问题部分的代码:

;code in initializing procedure
...
;Create mutex, if failure, abort resident
push ecx
push edx
VmmCall _CreateMutex, < 0, MUTEX_MUST_COMPLETE >
pop edx
pop ecx
or eax, eax
mov dMutex, eax
mov eax, ERROR_CREATE_MUTEX
jz lVSD_ret_CY
...

;==============================================================================
;
; Gate32_Write_Handler() - Handle writing routine for commands
;
; Entry: ebx is IOP
; Exit: al set to 0 to indicate calldown, set to 1 indication callback
; al set to 2 to indicate return without calldown or callback
;
; Destroys: eax
;
;==============================================================================
beginproc Gate32_Write_Handler

AssertIOP (ebx)

push edi
VmmCall Get_Cur_Thread_Handle ;use current thread handle as reenter flag (dInterFlag)
cmp edi, dInterFlag ;if it's reenter?
pop edi

xor eax, eax
jz lGWH_ret ;it's reenter, return to calldown

; enter mutex
push eax
push ecx
push edx
VmmCall _EnterMutex, <dMutex, 0>
pop edx
pop ecx
pop eax

; set current thread handle to dInterFlag
push edi
VmmCall Get_Cur_Thread_Handle
mov dInterFlag, edi
pop edi

Call Prv_Write_Handler ;该过程处理硬盘写操作,内部读写请求较多,耗时约10-500ms
mov dInterFlag, 0 ;clear reenter flag

push eax
push dMutex
VmmCall _LeaveMutex
add esp, 4
pop eax

lGWH_ret:
ret

endproc Gate32_Write_Handler
yehong 2000-03-02
  • 打赏
  • 举报
回复
致deepwater:我试过了,还是不行。我试着用提升优先级的办法,情况好一些,不是每次都死。大概有一半的机会不死。

15,472

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC 进程/线程/DLL
社区管理员
  • 进程/线程/DLL社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧