由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
Programming版 - C 多线程的一个问题
相关主题
请教一个c语言实现多线程的问题一个小问题
一道面试题C++ interdependence question
请问一个多线程与volatile关键字的问题。问个C++中重复删除指针的问题
问一声大牛,c++不用pointer怎么编程?作为返回值得实参是用指针还是引用比较好?
一个简单的小问题再问一个弱问题:为什么程序地址0-0x08000000是不可用的 (转载)
C++ Q05: pointer to constant variabledereference a NULL pointer in C
为什么我的Navigate2总是崩溃在错误的参数表版本里?纯虚函数问题
delete this problem问个程序问题
相关话题的讨论汇总
话题: ix话题: dword话题: lpvoid话题: winapi话题: hthread
进入Programming版参与讨论
1 (共1页)
e***n
发帖数: 286
1
我有这样一段程序:
// Define 10 subproblems of the same content
DWORD WINAPI sub1(LPVOID lpPara);
DWORD WINAPI sub2(LPVOID lpPara);
...
DWORD WINAPI sub10(LPVOID lpPara);
// Define function pointer array
DWORD (WINAPI *PtrSub[10])(LPVOID = {sub1, sub2, ..., sub10};
// Start 10 multithreads
HANDLE hThread[10];
for(int ix = 0; ix < 10; ++ix)
hThread[ix] = CreateThread(NULL, 0, PtrSub[ix], NULL, 0, NULL);
for(int ix = 0; ix < 10; ++ix)
CloseHandle(hThread[ix]);
//...
while(SOLVED) Sleep(50);
//...
。。。
c********e
发帖数: 383
2
the reason for the interface mismatch is that a normal member function has
a implicit augment -> this pointer passed in, and the way using object array
instead of function pointer array virtually does not performance
enhancement.
btw, if u are doing c programming why would you want to do object?
if your sub1-10 are the same, you can just define one sub function for all
threads to use, however, you can pass in different augments into the sub
when you
create threads

【在 e***n 的大作中提到】
: 我有这样一段程序:
: // Define 10 subproblems of the same content
: DWORD WINAPI sub1(LPVOID lpPara);
: DWORD WINAPI sub2(LPVOID lpPara);
: ...
: DWORD WINAPI sub10(LPVOID lpPara);
: // Define function pointer array
: DWORD (WINAPI *PtrSub[10])(LPVOID = {sub1, sub2, ..., sub10};
: // Start 10 multithreads
: HANDLE hThread[10];

t****t
发帖数: 6806
3
干嘛不在sub里自己开数据结构?

array

【在 c********e 的大作中提到】
: the reason for the interface mismatch is that a normal member function has
: a implicit augment -> this pointer passed in, and the way using object array
: instead of function pointer array virtually does not performance
: enhancement.
: btw, if u are doing c programming why would you want to do object?
: if your sub1-10 are the same, you can just define one sub function for all
: threads to use, however, you can pass in different augments into the sub
: when you
: create threads

c********e
发帖数: 383
4
我觉得他现在就是怎么干的,但是他copy了9次那个func或者聪明一点9次那个func
pointer.

【在 t****t 的大作中提到】
: 干嘛不在sub里自己开数据结构?
:
: array

t****t
发帖数: 6806
5
你真闲啊

【在 c********e 的大作中提到】
: 我觉得他现在就是怎么干的,但是他copy了9次那个func或者聪明一点9次那个func
: pointer.

c********e
发帖数: 383
6
坐在地板上,电脑屏幕也在地板上...过两天也没床了
更没有wow玩,
能不闲么

【在 t****t 的大作中提到】
: 你真闲啊
t****t
发帖数: 6806
7
啥时候开始上班?

【在 c********e 的大作中提到】
: 坐在地板上,电脑屏幕也在地板上...过两天也没床了
: 更没有wow玩,
: 能不闲么

c********e
发帖数: 383
8
h1b办不下来我也没办法,还没辞职呢,天天磨洋工

【在 t****t 的大作中提到】
: 啥时候开始上班?
e***n
发帖数: 286
9
终于搞定了, 其实就是定义一个 sub 就行了, 开多个线程调用, 重新把数据结构整理
了一下, 把公用的数据和本线程内局部数据分清楚就行了, 第一次用多线程, 觉得还真
是不错. 我这是个搜索算法, 开 2 个线程后用了个很简单的规则来交换线程间信息,
感觉多线程对搜索算法效率是有所提高, 但是开 3 个线程以上的性能提高就没那么显
著了.

【在 e***n 的大作中提到】
: 我有这样一段程序:
: // Define 10 subproblems of the same content
: DWORD WINAPI sub1(LPVOID lpPara);
: DWORD WINAPI sub2(LPVOID lpPara);
: ...
: DWORD WINAPI sub10(LPVOID lpPara);
: // Define function pointer array
: DWORD (WINAPI *PtrSub[10])(LPVOID = {sub1, sub2, ..., sub10};
: // Start 10 multithreads
: HANDLE hThread[10];

a**u
发帖数: 5
10
playing with multi-thread programming is interesting....
but in terms of searching... only if you have long waiting time in one
thread, such as wait for internet response, otherwise you will have overhead
when using multi-thread. IMHO
e******r
发帖数: 220
11
which compiler did you use for this thing? Thanks
BTW: MICROSOFT VISUAL STUDIO sucks, I even couldn't see race condition when
I test the code and expect to see race condition.


【在 e***n 的大作中提到】
: 我有这样一段程序:
: // Define 10 subproblems of the same content
: DWORD WINAPI sub1(LPVOID lpPara);
: DWORD WINAPI sub2(LPVOID lpPara);
: ...
: DWORD WINAPI sub10(LPVOID lpPara);
: // Define function pointer array
: DWORD (WINAPI *PtrSub[10])(LPVOID = {sub1, sub2, ..., sub10};
: // Start 10 multithreads
: HANDLE hThread[10];

1 (共1页)
进入Programming版参与讨论
相关主题
问个程序问题一个简单的小问题
问个数组地址的问题C++ Q05: pointer to constant variable
C++ Q87: What is wrong with this swap function? (转载)为什么我的Navigate2总是崩溃在错误的参数表版本里?
c ptr questiondelete this problem
请教一个c语言实现多线程的问题一个小问题
一道面试题C++ interdependence question
请问一个多线程与volatile关键字的问题。问个C++中重复删除指针的问题
问一声大牛,c++不用pointer怎么编程?作为返回值得实参是用指针还是引用比较好?
相关话题的讨论汇总
话题: ix话题: dword话题: lpvoid话题: winapi话题: hthread