你的代码中出现了错误。 _beginthread
函数需要一个指向线程入口点函数的指针作为第一个参数,而你却直接传递了 function1(recipe)
的调用结果。这导致编译器无法将 Module_Status
类型转换为 _beginthread_proc_type
类型。
要解决这个问题,你应该创建一个静态或全局函数,并将其作为线程入口点,在该函数内部调用 function1(recipe)
。下面是修改后的示例代码:
unsigned int __stdcall ThreadFunc(void* arg) {
Recipe& recipe = *static_cast<Recipe*>(arg);
printf("set plate temp thread start\n");
if (SYS_ABORTED == RUN_FUNCTIONF(Temp_Ctrl, "set-plate %.2f %.2f %.2f", recipe.GetSingleStep().plateTarget, recipe.GetSingleStep().plateAlarm, recipe.GetSingleStep().plateStop))
{
return Global::ModuleStatus(SYS_ABORTED);
}
_endthread();
return 0;
}
// 在合适的位置调用 _beginthread
Recipe myRecipe; // 假设有一个 Recipe 对象
_beginthread(ThreadFunc, 0, &myRecipe);
在上述示例中,我们创建了名为 ThreadFunc
的静态函数作为线程入口点,在其中将 arg
转换为 Recipe&
引用,并进行相应操作。然后我们通过 _beginthread
调用 ThreadFunc
并传递相关参数。
请根据你的实际需求和代码结构进行适当修改。
内容由零声教学AI助手提供,问题来源于学员提问