在过去的几周中,我一直很忙地创建基于Fine Tsynedit组件的自定义内部代码编辑器。
编辑线需要进行一些背景处理,以验证用户输入并突出潜在的错误语法。该处理是每500毫秒触发的,由主形式的A ttimer 触发。
验证器线程在填充
的每条线上迭代std::map<int, String>
使用行号/错误文本。
tsynedit的 onspeciallinecolor 事件正在寻找地图中的相应行,如果 isempty()是false,则行的背景变成红色。
要使合成足够充分的线程安全,而无需使用 synchronize()或某些 winapi 消息的消息,我的想法是,使用某种代码这个:
#include <memory>
#define BOOST_THREAD_USE_LIB
namespace boost { extern "C" void tss_cleanup_implemented(void) {}; }
#include <boost/thread.hpp>
class TMySynEdit : public TSynEdit
{
private:
boost::mutex FMutexLines;
TStrings* GetLines()
{
boost::lock_guard<boost::mutex> guard(FMutexLines);
return TSynEdit::Lines;
}
void SetLines(TStrings* ALines)
{
boost::lock_guard<boost::mutex> guard(FMutexLines);
TSynEdit::Lines = ALines;
}
public:
__fastcall TMySynEdit(TComponent* AOwner)
: TSynEdit(AOwner)
{}
virtual __fastcall ~TMySynEdit()
{}
__property TStrings* Lines = {read=GetLines, write=SetLines};
};
用线程安全(?)一个。
计时器触发的线程是在 boost :: thread 中运行的解析功能。
我现在的问题是:这是一个足够的解决方案,还是我在这里错过了一些东西?
感谢雷米(Remy),我可能会回到工作时返回到非线程版本。