欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

线程里面当前状态变换后一定要将当前状态给之前状态

程序员文章站 2022-04-06 21:34:43
...

线程里面进行变量的变换,定时器中也进行访问时候,线程里面

线程里面的开关量,利用完毕,一定要立即改变值,因为线程的优先级高

一、目的

1、问题:线程里面if判断条件里面当前状态和上次状态有变化后,大括号中如果没有立即将当前状态给上一次状态,大括号里面就可能会执行很多次

 

二、参考

1、

 

三、操作

1、

  • 总结:因为线程里面的优先级比较高,如果不立即将if里面当前状态给之前状态,大括号里面可能就会执行多次

线程里面当前状态变换后一定要将当前状态给之前状态

	if (pThis->m_tUsb5538.byDISts[pThis->m_tUsb5538.iChannel_in_youBeng_qiDong_btn]==pThis->m_tUsb5538.in_value
			&&pThis->m_tUsb5538.byDISts_last[pThis->m_tUsb5538.iChannel_in_youBeng_qiDong_btn]==(pThis->m_tUsb5538.in_value+1)%2	)
		{
			if (pThis->m_tUsb5538.byDISts[pThis->m_tUsb5538.iChannel_in_shiNei_stop_btn]==(pThis->m_tUsb5538.in_value+1)%2		
				&&pThis->m_tUsb5538.byDISts[pThis->m_tUsb5538.iChannel_in_youBeng_run]==(pThis->m_tUsb5538.in_value+1)%2		)
			{
				//按下设备间的油泵启动启动按钮&&室内急停按钮是松开状态&&油泵没有运行输入
				pThis->m_tUsb5538.byDISts_last[pThis->m_tUsb5538.iChannel_in_youBeng_qiDong_btn]=pThis->m_tUsb5538.byDISts[pThis->m_tUsb5538.iChannel_in_youBeng_qiDong_btn];
				pThis->m_tUsb5538.byDISts_last[pThis->m_tUsb5538.iChannel_in_shiNei_stop_btn]=pThis->m_tUsb5538.byDISts[pThis->m_tUsb5538.iChannel_in_shiNei_stop_btn];
				pThis->m_tUsb5538.byDISts_last[pThis->m_tUsb5538.iChannel_in_youBeng_run]=pThis->m_tUsb5538.byDISts[pThis->m_tUsb5538.iChannel_in_youBeng_run];

				::PostMessage(pThis->m_hWnd,WM_KEYUP,VK_NUMPAD0,NULL);					
			}
		}

 

相关标签: 编程思想