|
[求助]疑惑
我在MSDN中查了下,看来我要理解一下消息机制。 Before CreateWindow() returning, CreateWindow() sends a WM_CREATE message to the window procedure 所以在WM_CREATE中调用CreateWindow() 大概是 sends a WM_CREATE message后window procedure中没对应处理代码导致的吧 |
|
[求助]请教下,TLS是用来做什么的。
线程自己的变量?说的就是线程局部变量,用自己的变量你试试,上面 的程序你又得写不少代码,TLS的关键在于系统内部把局部变量和线程关联起来,线程只能访问自己关联的数据,这样就很方便了。 |
|
[求助]请教下,TLS是用来做什么的。
我的一点认识: TLS线程局部存储,用于存储线程局部数据。TLS机制为进程中每个线程关联若干个数据。各个线程通过TLS 分配的全局索引来访问自己关联的数据。 Windows为每一个进程维护了一个数组,进程中每个线程又有一个对应数组,进程的数组用来指示线程数组中哪一个成员在使用中。线程数组则保存自己的数据。 这是王艳平书上一个例子,斑竹看下吧。欲知详情,请看《windows程序设计》(王艳平) #include <stdio.h> #include <windows.h> #include <process.h> // 利用TLS记录线程的运行时间 DWORD g_tlsUsedTime; void InitStartTime(); DWORD GetUsedTime(); UINT __stdcall ThreadFunc(LPVOID) { int i; // 初始化开始时间 InitStartTime(); // 模拟长时间工作 i = 10000*10000; while(i--) { } // 打印出本线程运行的时间 printf(" This thread is coming to end. Thread ID: %-5d, Used Time: %d \n", ::GetCurrentThreadId(), GetUsedTime()); return 0; } int main(int argc, char* argv[]) { UINT uId; int i; HANDLE h[10]; // 通过在进程位数组中申请一个索引,初始化线程运行时间记录系统 g_tlsUsedTime = ::TlsAlloc(); // 令十个线程同时运行,并等待它们各自的输出结果 for(i=0; i<10; i++) { h[i] = (HANDLE)::_beginthreadex(NULL, 0, ThreadFunc, NULL, 0, &uId); } for(i=0; i<10; i++) { ::WaitForSingleObject(h[i], INFINITE); ::CloseHandle(h[i]); } // 通过释放线程局部存储索引,释放时间记录系统占用的资源 ::TlsFree(g_tlsUsedTime); return 0; } // 初始化线程的开始时间 void InitStartTime() { // 获得当前时间,将线程的创建时间与线程对象相关联 DWORD dwStart = ::GetTickCount(); ::TlsSetValue(g_tlsUsedTime, (LPVOID)dwStart); } // 取得一个线程已经运行的时间 DWORD GetUsedTime() { // 获得当前时间,返回当前时间和线程创建时间的差值 DWORD dwElapsed = ::GetTickCount(); dwElapsed = dwElapsed - (DWORD)::TlsGetValue(g_tlsUsedTime); return dwElapsed; } |
|
[求助]一个宏
谢谢你!!这么大晚还回答。答复很详细。我调试下市这样的 |
|
|
|
[分享]你们是否同样苦恼。
怎么成这样了啊,我这么差也不是这样啊,静下心来学吧 |
|
[分享]网上有人分享《加密与解密》第三版完整PDF版了
要看纸的,不然看不出名堂 |
|
[原创]苦恼
你可以找数学系的书看看啊,今天看复变,快晕了,还是看罗云彬的书有劲 |
|
[原创]苦恼
说的也是啊,尽量学吧 |
|
[原创]有河南郑州的朋友请进来
有没有郑州大学的?加我QQ:330240295 |
|
|
|
[求助]这是为什么呢?
我强烈建议你去去看看王爽老师的书 |
|
[分享]民间电脑高手
看到了希望 |
操作理由
RANk
{{ user_info.golds == '' ? 0 : user_info.golds }}
雪币
{{ experience }}
课程经验
{{ score }}
学习收益
{{study_duration_fmt}}
学习时长
基本信息
荣誉称号:
{{ honorary_title }}
能力排名:
No.{{ rank_num }}
等 级:
LV{{ rank_lv-100 }}
活跃值:
在线值:
浏览人数:{{ visits }}
最近活跃:{{ last_active_time }}
注册时间:{{ user_info.create_date_jsonfmt }}
勋章
兑换勋章
证书
证书查询 >
能力值