【发布时间】:2016-03-21 19:31:36
【问题描述】:
我有一个 C++ dll,我使用 boost library 来实现多线程,然后我想在 C# 程序中使用这个 dll。
我做到了,我的程序按预期运行,我的系统没有任何问题。
当我使用Advanced Installer 创建安装程序并将其作为新程序安装在我的系统中时(我已经在其上开发了应用程序),一切都很好,没有任何问题。但是当我在其他系统上安装这个程序并运行它时,一开始程序会正常运行,但是当它想创建线程并运行它们时,程序就会停止。
我在 C++ dll 中的部分代码如下:
struct ThreadParams
{
int thetaStart,
thetaEnd,
rStart;
vector<string> files;
}thParams;
const int NUM_OF_THREADS = 5;
extern "C"
{
__declspec(dllexport) int __stdcall Start(const char *path)
{
thParams.files = listFilesInDirectory(path);
int step = thParams.files.size()/NUM_OF_THREADS;
thParams.rStart = 1;
thParams.thetaStart = 0;
thParams.thetaEnd = 360;
boost::thread_group tgroup;
FILE *output_text;
char *buffer = new char[128];
for (int i = 0; i < NUM_OF_THREADS; i++)
{
sprintf(buffer,"out%d.txt",i+1);
output_text = fopen(buffer,"wt");
int start = i*step;
int end = (thParams.files.size() - (start+step)) >= step ? (start+step) : thParams.files.size();
tgroup.create_thread(boost::bind(ThreadProcess,start,end,output_text,i+1));
}
tgroup.join_all();
_fcloseall();
delete buffer;
buffer = NULL;
}
}
void ThreadProcess(int start, int end, FILE *out, int threadID)
{
for(int i = start; i < end; ++i)
{
fprintf(out,"%s\n",thParams.files[i].c_str());
}
}
谁能帮我解决这个问题,好吗?
提前致谢。
【问题讨论】:
标签: c# c++ multithreading boost-thread concurrent-programming