在 LabWindows/CVI 中发送参数到线程回调函数
主要软件:
主要软件版本: 8.0
主要软件修正版本: N/A
次要软件: N/A
问题: 我想要在 LabWindows/CVI 中发送参数到线程回调函数。我应该如何做?
解答: 启动第二个线程并让它执行需要使用
CmtScheduleThreadPoolFunction()
函数的函数。这个函数通知
CmtNewThreadPool()
函数创建的线程池,您就可以从线程池的一个线程中执行函数。
第二个线程执行的线程回调函数必须具有下列原型:
int CVICALLBACK ThreadFunction (void *functionData);
CmtScheduleThreadPoolFunction()
函数指定执行的函数以及传递到该函数的数据。函数的第二个输入参数
threadFunction 表示函数执行的调度。第三个参数
threadFunctionData 表示传递到函数的数据。这个参数使用指向 void 的指针。例如,假设字符串需要传递到线程回调函数,调用函数代码类似于下列代码:
char *test;
test = malloc(x * sizeof(char*));
strcpy(test, "Here is a test string");
CmtScheduleThreadPoolFunction(poolHandle, ThreadFunction, test, NULL);
The thread callback function would look like:
int CVICALLBACK ThreadFunction(void *functionData)
{
// User interface contains a string control called STRING
SetCtrlVal(panelHandle, PANEL_STRING, functionData);
.........
return 0;
}
参看附件中的例程以了解传递一个包含多个成员的结构体到线程回调函数的方法。
相关链接: Developer Zone Tutorial: Multithreading in LabWindows/CVI
附件:
报告日期: 08/30/2006
最近更新: 12/19/2007
文档编号: 401LUSGJ
Other Support Options
Ask the NI Community
Collaborate with other users in our discussion forums
Request Support from an Engineer
A valid service agreement may be required, and support options vary by country.