分类目录
文章索引模板
Pause Resume Thread List - 十月 24, 2009 by yippee

// pausep.cpp : Defines the entry point for the console application.
//


#include “stdafx.h”
#include “pausep.h”
#ifdef _DEBUG
#define new DEBUG_NEW
#endif


using namespace std;


BOOL PauseResumeThreadList(DWORD dwOwnerPID, bool bResumeThread)
{
    HANDLE        hThreadSnap = NULL;
    BOOL          bRet        = FALSE;
    THREADENTRY32 te32        = {0};
 
    // Take a snapshot of all threads currently in the system.


    hThreadSnap = CreateToolhelp32Snapshot(TH32CS_SNAPTHREAD, 0);
    if (hThreadSnap == INVALID_HANDLE_VALUE)
        return (FALSE);
 
    // Fill in the size of the structure before using it.


    te32.dwSize = sizeof(THREADENTRY32);
 
    // Walk the thread snapshot to find all threads of the process.
    // If the thread belongs to the process, add its information
    // to the display list.
 
    if (Thread32First(hThreadSnap, &te32))
    {
        do
        {
            if (te32.th32OwnerProcessID == dwOwnerPID)
            {
    HANDLE hThread = OpenThread(THREAD_SUSPEND_RESUME, FALSE, te32.th32ThreadID);
    if (bResumeThread)
    {
     cout << _T(“Resuming Thread 0x”) << cout.setf( ios_base::hex ) << te32.th32ThreadID << ‘\n’;
     ResumeThread(hThread);
    }
    else
    {
     cout << _T(“Suspending Thread 0x”) << cout.setf( ios_base::hex ) << te32.th32ThreadID << ‘\n’;
     SuspendThread(hThread);
    }
    CloseHandle(hThread);
            }
        }
        while (Thread32Next(hThreadSnap, &te32));
        bRet = TRUE;
    }
    else
        bRet = FALSE;          // could not walk the list of threads
 
    // Do not forget to clean up the snapshot object.
    CloseHandle (hThreadSnap);
 
    return (bRet);
}


BOOL ProcessList()
{
    HANDLE         hProcessSnap = NULL;
    BOOL           bRet      = FALSE;
    PROCESSENTRY32 pe32      = {0};
 
    //  Take a snapshot of all processes in the system.
    hProcessSnap = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);


    if (hProcessSnap == INVALID_HANDLE_VALUE)
        return (FALSE);
 
    //  Fill in the size of the structure before using it.
    pe32.dwSize = sizeof(PROCESSENTRY32);
 
    //  Walk the snapshot of the processes, and for each process,
    //  display information.


    if (Process32First(hProcessSnap, &pe32))
    {
        do
        {
   cout << _T(“PID\t”) << pe32.th32ProcessID << ‘\t’ << pe32.szExeFile << ‘\n’;
        }
        while (Process32Next(hProcessSnap, &pe32));
        bRet = TRUE;
    }
    else
        bRet = FALSE;    // could not walk the list of processes
 
    // Do not forget to clean up the snapshot object.


    CloseHandle (hProcessSnap);
    return (bRet);
}


 


int _tmain(int argc, TCHAR* argv[], TCHAR* /* envp[] */)
{
 if (argc <= 1)
 {
  cerr << _T(“Usage: pausep PID /r\n”);
  cerr << _T(“/r: resumes the execution of PID\n”);
  ProcessList();
  return 1;
 }
 else
 {
  DWORD pid = _ttoi(argv[1]);
  if (pid == 0)
  {
   cerr << _T(“Invalid PID number: “) << pid << ‘\n’;
   return 1;
  }
  else
   PauseResumeThreadList(pid, (argc > 2) && (!_tcsicmp(argv[2], _T(“/r”))));
 }


 return 0;
}

标签:
20090718 wordpress OK - 八月 18, 2009 by yippee

搞了半天,终于搞定了。

由于空间PHP版本的问题,没有办法使用SQLITE

本机很快就已经搭建完成。

数据也很快导入了。

但是发布出现两个问题

1、当部署到服务器的时候,安装插件的时候,发现TAG不正常显示,直接搜索插件也提示出现未知错误。原本是把自己本机弄好的直接上传,因此重新弄了一次。重新进行干净安装。但是奇怪的是,问题还是存在,然后在网吧又是正常的。

 由于服务器速度问题,数据导入倒出问题,导致折腾了好几天。

2、数据错位问题,也许由于垃圾留言的影响,导致丢了几个BLOG,结果导入的时候没有发现,直接忽略空白内容,导致错位,标题和内容失配,只好又重新来过,这次在网吧折腾,好像速度会快些。

主题采用的是:Contrast Style 1.1 三栏,因为比较喜欢堆彻东西。

插件用了不少

Antispam Bee 屏蔽垃圾留言的

Akismet 自带反垃圾留言的,但是不知道到哪里去找被它砍掉的留言(上线才半天,报告干掉了24个)

Disable Canonical URL Redirection WP默认首页为不带index.php

Genki Announcement 公告栏

Peter’s Custom Anti-Spam 增加留言验证码

Simple Tags 智能标签,这个比较强大

Some Chinese Please 屏蔽纯洋文留言,上次就被阿拉伯文搞死两个BLOG

Wordpress Thread Comment 嵌套留言

WP-PageNavi 页码导航 但是不能输入

WP-PostViews BLOG点击数

WP-T-Wap WAP插件

WP Kit CN 强大 

用来解决官方 WordPress 没有照顾到的中文相关问题。使用这个插件,你可以显示随机文章,最新留言(最新引用),留言最多文章,发表评论最多的网友,还有真正的文章摘要,等等,真正截断,没有乱码。此插件在桑葚基础上修改,支持最新评论显示表情。支持指定最新评论截断字数。使用了对中文兼容更好的截断算法,现在控制字数更精确了。

Genki AnnouncementSCP SettingPageNaviPostViewsWP-T-WAPSimple TagsWP Kit CN

标签:, , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , ,
20090115 c# suspend thread - 八月 18, 2009 by yippee

c#线程_网络技术
http://hi.baidu.com/gexiangyu/blog/item/113f34296f2590ff99250a96.html

.NET2.0里说Thread.Suspend 方法已经过时,哪该用哪个方法呢? .NET技术 / C# – CSDN社区 community.csdn.net
http://topic.csdn.net/t/20061209/21/5219250.html

回复: 在做一个小软件里面含有下载文件.线程如何暂停和继续啊?自带的方法过时了 – 微软中文技术论坛(MSDN and TechNet)
http://forums.microsoft.com/china/ShowPost.aspx?PostID=3795307&SiteID=15

C#线程问题Threading.Thread
http://www.fish888.com/C-Threading-Thread-t174322

Thread.Suspend()已过时…多线程
http://topic.csdn.net/u/20081228/10/33340449-ce97-4b63-99bf-54f8d458ea05.html
volatile bool paused; ManualResetEvent resumeEvent = new ManualResetEvent(false); void MyThread() &leftsign; for (int i = 0; i < 100; i++) &leftsign; if (paused) &leftsign; resumeEvent.WaitOne(); &rightsign; DoWork(); &rightsign; &rightsign; void Pause() &leftsign; resumeEvent.Reset(); paused = true; &rightsign; void Resume() &leftsign; paused = false; resumeEvent.Set(); &rightsign;

c# 线程同步: 详解lock,monitor,同步事件和等待句柄以及mutex – 老刘忙不忙 – 博客园
http://www.cnblogs.com/xd125/archive/2007/12/12/992406.html

CSDN技术中心 volatile编写多线程程序的好帮手
http://dev.csdn.net/develop/article/83/83923.shtm

volatile_百度百科
http://baike.baidu.com/view/608706.htm

Thread.Suspend()已过时…多线程
http://topic.csdn.net/u/20081228/10/33340449-ce97-4b63-99bf-54f8d458ea05.html
volatile bool paused; ManualResetEvent resumeEvent = new ManualResetEvent(false); void MyThread() &leftsign; for (int i = 0; i < 100; i++) &leftsign; if (paused) &leftsign; resumeEvent.WaitOne(); &rightsign; DoWork(); &rightsign; &rightsign; void Pause() &leftsign; resumeEvent.Reset(); paused = true; &rightsign; void Resume() &leftsign; paused = false; resumeEvent.Set(); &rightsign;

c# 线程同步: 详解lock,monitor,同步事件和等待句柄以及mutex – 老刘忙不忙 – 博客园
http://www.cnblogs.com/xd125/archive/2007/12/12/992406.html

Thread问题 .NET技术 / C# – CSDN社区 community.csdn.net
http://topic.csdn.net/t/20060509/20/4739806.html
在.net2.0中该方法已经过时了,建议不要使用。 
  [ObsoleteAttribute("Thread.Suspend   has   been   deprecated.     Please   use   other   classes   in   System.Threading,   such   as   Monitor,   Mutex,   Event,   and   Semaphore,   to   synchronize   Threads   or   protect   resources.     http://go.microsoft.com/fwlink/?linkid=14202",   false)]   
  public   void   Suspend   ()  

标签:,

20081028 c# threads back worker - 六月 28, 2009 by yippee

http://big5.webasp.net/article/17/16513_print.htm

Socket.Connect 方法 (EndPoint) (System.Net.Sockets)
http://msdn.microsoft.com/zh-cn/vstudio/ych8bz3x(VS.80).aspx

包包版网络游戏大厅+桥牌系统 3.从登录说起 – 包建强的开源地带 – 博客园
http://www.cnblogs.com/Jax/archive/2008/07/30/1252679.html

包包版网络游戏大厅+桥牌系统 4.终于可以聊天了 – 包建强的开源地带 – 博客园
http://www.cnblogs.com/Jax/archive/2008/07/31/1257473.html

包包版网络游戏大厅+桥牌系统 附录1 通信协议 – 包建强的开源地带 – 博客园
http://www.cnblogs.com/Jax/archive/2008/07/21/1247969.html

包包版网络游戏大厅+桥牌系统 2.游戏大厅的基本架构 – 包建强的开源地带 – 博客园
http://www.cnblogs.com/Jax/archive/2008/07/19/1246720.html

Programming .Net component 2nd (部分中文翻译2) – 俩醒叁醉的博客 – CSDNBlog
http://blog.csdn.net/Silicon_Fado/archive/2007/01/18/1486257.aspx

200809091958 – deadmeat on RSS Mixer
http://www.rssmixer.com/mixes/9145-200809091958-deadmeat

总结.NET中异步通讯[读win control] – sharplife – 博客园
http://www.cnblogs.com/sharplife/archive/2008/05/30/644272.html

C#线程系列讲座(3):线程池和文件下载服务器 – 真的有外星人吗? – 博客园
http://www.cnblogs.com/nokiaguy/archive/2008/07/19/1246299.html
 ThreadPool.SetMaxThreads

C#使用线程池验证代理,,,_和谐_离开的地盘
http://hi.baidu.com/4tr3iusdhu/blog/item/b9d3f64e377f2eced0c86a5a.html

ThreadPool问题_百度知道
http://zhidao.baidu.com/question/32362474.html

异步调用与多线程关系的众多不同观点_等待着别人给幸福的人,往往过得都不怎么幸福
http://hi.baidu.com/freeprogman/blog/item/ec7f0c2a7be07f3b5343c18b.html

ThreadPool(线程池) in .Net – Rickie Lee\’s blog – 博客园
http://www.cnblogs.com/rickie/archive/2004/11/23/67275.html

C#里面如何限制多个线程数量,即最多开启5个线程,其他线程等待有线程退出后再开启,最好有源码._软界知道
http://www.softwelt.com/Know/KnowDetail-3204439.html
http://www.cnblogs.com/rickie/archive/2004/11/23/67275.html

ThreadPool的 SetMaxThreads 设置了4000 但是 到 1390多的时候就终止了
http://topic.csdn.net/u/20080620/21/b870da88-f087-43c2-9611-b8ea4e296870.html?2074961622

C#线程系列讲座(3):线程池和文件下载服务器 – 真的有外星人吗? – 博客园
http://www.cnblogs.com/nokiaguy/archive/2008/07/19/1246299.html
在 .NET 2.0 中, ThreadPool 中默认最大工作线程是每 CPU 25个。
在 .NET 3.5 中, ThreadPool 中默认最大工作线程是每 CPU 250个。

请问C#里边如何设定线程池中线程的数量 .NET技术 / C# – CSDN社区 community.csdn.net
http://topic.csdn.net/t/20040805/19/3246657.html
QueueUserWorkItem

如何在新的线程里调用主窗体的控件 – IT者
http://www.itzhe.cn/news/20080128/66388.html

Gone with wind
http://myaccessweb.info/index.php?hl=f5&q=uggc%3A%2F%2Fglenrygbat.oybtfcbg.pbz%2F

实现异步登录 – 改变不了环境就适应环境、适应不了环境就换个环境 – 博客园
http://www.cnblogs.com/johnxie/articles/1262207.html

在C#中跨线程访问Winform控件 – 挑战自我,超越无限 – 博客园
http://www.cnblogs.com/happy555/archive/2007/05/18/751110.aspx

C#中的多线程-使用多线程 – C#&line;DOTNET – yaosansi\’s Blog
http://www.yaosansi.com/post/1170.html

BackgroundWorker_上善若水
http://hi.baidu.com/li_hang/blog/item/e54f9152c2bf730e0df3e332.html

C#中的多线程-使用多线程 – C#&line;DOTNET – yaosansi\’s Blog
http://www.yaosansi.com/post/1170.html

包包版网络游戏大厅+桥牌系统 序 – 包建强的开源地带 – 博客园
http://www.cnblogs.com/Jax/archive/2008/07/05/1236246.html

包包版网络游戏大厅+桥牌系统 3.从登录说起 – 包建强的开源地带 – 博客园
http://www.cnblogs.com/Jax/archive/2008/07/20/1252679.html

八款IE插件 八种方便
http://www.newsunday.com/post/726.html

IEForge – bends IE to your will &line; InlineSearch / HomePage
http://www.ieforge.com/InlineSearch/HomePage

IE7Pro 2.4.3 Final┊广告屏蔽/恢复风格/隐藏搜索等功能┊多国语言绿色免费版
http://www.greendown.cn/soft/6819.html

IE伴侣(IEmate) V1.0.9┊是基于IE 浏览器的增强工具软件┊简体中文绿色免费版
http://www.greendown.cn/soft/11328.html
IE伴侣

深度软件论坛 – 深度,值得深入!
http://soft.deepin.org/read.php?tid=244919

ieplus与iepro的问题 – Vista『问答帮助』 – Vista之家论坛 – Windows Vista论坛,Vista SP1,Vista主题网站,Windows Vista下载
http://bbs.vista123.com/viewthread.php?tid=75173&extra=page%3D874%26amp%3Bfilter%3D0%26amp%3Borderby%3Dreplies%26amp%3Bascdesc%3DDESC

IEPRO和IEPLUS使用后的体会&line;『应用交流专区』 – ★- 欢迎光临绿影在线论坛 -★ – bbs.greendown.cn
http://bbs.greendown.cn/viewthread.php?tid=125447

用VS2005开发BHO揭开IE插件的神秘面纱
http://www.zhangsichu.com/blogview.asp?Content_Id=108

VC++开发BHO插件,定制IE浏览器_智佳精控技术小组
http://hi.baidu.com/kaixinlaohe/blog/item/d9863c9b2a3066b5c9eaf4da.html

VC知识库文章 – 如何使用BHO定制你的Internet Explorer浏览器
http://www.vckbase.com/document/viewdoc/?id=1426

标签:,
20080907 wpf thread 线程 - 五月 5, 2009 by yippee

.NET BLOG &line; Create WPF Applications without XAML
http://www.dotnet-blog.com/index.php/2008/04/21/create-wpf-applications-without-xaml/

Using WPF without XAML, the WinFX SDK or VS Extensions – Vista Forums
http://www.vistax64.com/avalon/332-using-wpf-without-xaml-winfx-sdk-vs-extensions.html

CodeProject: WPF Windows: Code-based layout versus XAML. Free source code and programming help
http://www.codeproject.com/KB/WPF/WinFXWindows.aspx

C# .NET InvalidOperationException – But
http://www.eggheadcafe.com/community/aspnet/2/71725/invalidoperationexception.aspx

InvalidOperationException was unhandled, Visual Basic .NET, C#,VB.NET,XAML,.NET
http://www.c-sharpcorner.com/Forums/ShowMessages.aspx?ThreadID=37047

CodeProject: WPF Unit Testing. Free source code and programming help
http://www.codeproject.com/KB/WPF/unittestingwpf.aspx
t runner will show you the red light and tell you: InvalidOperationException failed to set the specified COM apartment state. If you try

System.InvalidOperationException : Windows Presentation Foundation (WPF) : .NET Development : MSDN Forums
http://forums.msdn.microsoft.com/en-US/wpf/thread/313481a4-02f3-47f5-aded-3cd486c854c9/

CodeProject: WPF Diagram Designer – Part 4. Free source code and programming help
http://www.codeproject.com/KB/WPF/WPFDiagramDesigner_Part4.aspx?fid=1147746&select=2523036&fr=26

CodeProject: Beginners Guide To Threading In .NET Part 5 of n. Free source code and programming help
http://www.codeproject.com/KB/threads/ThreadingDotNet5.aspx
SendOrPostCallback

CodeProject: Dynamic User Interfaces in WPF. Free source code and programming help
http://www.codeproject.com/KB/WPF/DynamicUIs.aspx

WPF Threading Tips
http://blog.falafel.com/2008/05/15/WPFThreadingTips.aspx

简易滚动信息显示小程序(源代码)图 – zackyVista – 博客园
http://www.cnblogs.com/zackyVista/archive/2006/09/28/517245.html

我自己写的winfx新闻显示小程序,有源码(图) – zackyVista – 博客园
http://www.cnblogs.com/zackyVista/archive/2006/07/03/441723.html

Data Binding
http://msdn.microsoft.com/en-us/library/ms750612.aspx

Properties
http://msdn.microsoft.com/en-us/library/ms753192.aspx

cy\’s dotnet blog – 博客园
http://caoyang.cnblogs.com/

WPF中UI线程和工作线程的交流 – zackyVista – 博客园
http://www.cnblogs.com/zackyVista/archive/2006/07/03/441192.html

反馈: XAML – this.Dispatcher.Invoke(DispatcherPriority, Delegate, OBJECT, params object[] args)
http://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=331257

sunshaking炮炮 - 图形学: UI 线程如何在自己的线程中处理工作线程的事件?
http://alphasun.spaces.live.com/Blog/cns!705A0F31B3F031CC!1837.entry

\’Dispatcher processing has been suspended\’ InvalidOperationException when calling ShowDialog : Windows Presentation Foundation (WPF) : .NET Development : MSDN Forums
http://forums.msdn.microsoft.com/en-US/wpf/thread/44962927-006e-4629-9aa3-100357861442/

C# .NET InvalidOperationException – But
http://www.eggheadcafe.com/community/aspnet/2/71725/invalidoperationexception.aspx

How to: Create a C# WPF Application
http://msdn.microsoft.com/en-us/library/bb655895.aspx

WPF中使用调度程序构建反应速度更快的应用程序 – this.Study(DateTime.Now) – 博客园
http://www.cnblogs.com/zhouyinhui/archive/2007/09/16/894719.html

CodeProject: A WPF based irregular pop up window demo. Free source code and programming help
http://www.codeproject.com/KB/WPF/wpfpopup.aspx

WPF 学习笔记 – 2. Dispatcher – Q.yuhen
http://www.rainsts.net/article.asp?id=736

WPF的线程模型-开发频道-IT技术-天极网
http://dev.yesky.com/272/8130272.shtml

WPF 线程: 使用调度程序构建反应速度更快的应用程序
http://msdn.microsoft.com/zh-cn/magazine/cc163328.aspx#S5

用StructLayout特性限定声明结构或类 – 有个程序员 – CSDNBlog
http://blog.csdn.net/Ador3/archive/2008/07/23/2694967.aspx

WPF的线程模型 – 有个程序员 – CSDNBlog
http://blog.csdn.net/Ador3/archive/2008/08/21/2806223.aspx

WPF的线程模型 – this.Study(DateTime.Now) – 博客园
http://www.cnblogs.com/zhouyinhui/archive/2008/01/27/1055261.html

通过制作一个简单的时钟学习WPF中DispatcherTimer的使用 Level 100 – tonyqus.cn – 博客园
http://www.cnblogs.com/tonyqus/archive/2006/12/21/599334.html

请教各位关于WPF中的多线程问题
http://topic.csdn.net/u/20080224/10/ef752805-70ef-4a29-a266-32c89fdd3647.html

WPF的线程模型 – 第2页 &line; ITPUB &line;
http://tech.it168.com/msoft/2008-01-28/200801281629227_1.shtml

标签:, ,
20071023 linux schedule pthread_create - 七月 22, 2008 by yippee

20071023 linux schedule pthread_create
http://www.yippeesoft.com

调度的实质是资源的分配,系统通过不同的算法来实现资源的分配。一般unix采用动态优先调度,5.3BSD采用多级反馈,
windows采用抢先多任务调度,对于linux,则根据进程的不同性质采用不同的调度策略。linux的调度程序是一个
叫schedule()的函数,它决定是否要进行进程的切换,切换到哪个进程。

首先先来看看在哪些情况下要执行调度程序,即调度时机。
1 进程状态转换的时刻:进程终止,睡眠。
2 当前进程的时间片用完时。
3 设备驱动程序。
4 进程从中断,异常,系统调用返回到用户态时。
对于1,进程本身调用exit(),sleep()函数进行状态转换,这些函数会主动调用调度程序进行进程调度。
对于2,当进程的时间片用完时,即 current->counter = 0,则会调用调度程序
大部分PC机有两个时钟源,即RTC和OS时钟,RTC(real time clock)实时时钟,也叫CMOS时钟,是PC主机板上的一块芯片,
它表示的时间即我们一般理解的时间。OS时钟产生于PC主板上的定时/计数芯片,只有在开机时,由操作系统取得RTC中的
时间数据,然后初始化。它不是本质意义上的时钟,它是由可编程定时/计数器产生的输出脉冲触发中断而产生的。输出
脉冲的周期叫一个“时钟滴答”,它是linux的时间单位,操作系统根据当前时钟滴答的数目,就可以得到以秒或毫秒等为
单位的其他时间格式。在这里,我们把counter叫做进程的时间片,实际上它是时钟滴答的个数。例如,counter = 10,
则分配给进程的时间片是10个时钟滴答,因为linux的一个时钟滴答为10ms,则系统给进程的初始化时间片大小是
10 * 10ms = 100ms.
对于3,当设备驱动程序执行长而重复任务时,直接调用调度程序。在每次反复循环中,驱动程序都要检查 need_resched
的值,如果必要,则调用调度程序,主动放弃CPU。
对于4,因为进程从中断,异常或系统调用返回时,都要调用 ret_from_sys_call(),由这个函数进行调度标志检测,如果
必要,调用调度程序。

在每个时钟中断发生时,由 schedule(),do_timer()和ret_from_sys_call()这3个函数共同完成进程的选择和切换。
schedule() 进程调度函数,由它来完成进程的调度。
do_timer() 时钟函数,在时钟中断服务程序中被调用,完成系统时间的更新,进程时间片的更新等工作。更新后的进程
时间片 counter作用调度的主要依据 ret_from_sys_call(),系统调用返回函数,它是从中断,异常及系统调用返回
时的通用接口,主要作用是检测调度标志 need_resched决定是否要执行调度程序处理当前进程的任务,恢复当前进程
的环境使之继续执行。

在 task_struct结构中,进程的调度信息决定系统中哪个进程最应该运行。
1 need_resched:在调度时机到来时,检测这个域的值,如果为1,则调用schedule()。
2 counter:前面讲过,它时进程处于运行状态时所剩余的时钟滴答数,每次时钟到来时,这个值就会减1。
3 nice:进程的“静态优先级”,这个域决定counter的初值。只有通过nice(),POSIX.1bsched_setparam()或
  5.4BSD/SVR4 setpriority()系统调用才能改变进程的静态优先级。
4 rt_priority:实时进程的优先级。
5 policy:是使用于该进程的调度策略,从整体上区分实时进程和普通进程。实时进程优先于普通进程而运行,
可以通过sched_setscheduler()来改变调度策略。对于同一类型的不同进程,采用不同的标准来选择进程。对于普通
进程,选择进程的主要依据为counter和nice。对于实时进程,linux采用了两种调度策略,即FIFO(先来先服务)和
MM(时间片轮转调度)。因为实时进程具有一定程度的紧迫性,所以衡量一个实时进程是否应该运行,linux采用了
比较固定的标准。实时进程的counter只是用来表示该进程的剩余滴答数,并不作为衡量它是否值得运行的标准,
这和普通进程有区别。

移植linux,修改的主要就是和平台相关的那部分代码.linux里面和平台相关的代码
包括很多方面,比如boot过程,系统调用,中断处理,设备驱动,还有部分信号(软中断)处理
等,进程切换也有很小一部分平台相关代码.相对其它部分,我觉得这部分平台相关代码还
是相对简单的.

    schedule()是uClinux中实现进程调度的函数.通过一定算法,进行调度.假设有2各进
程a,b,a运行时,调用了schedule(),那么os就要从进程就绪队列中挑选一个合适的进程,
如果没有合适进程,则后面继续运行a,假设找到了合适进程b,则就要从当前进程a切换到b.
这个切换过程是在switch_to()中进行的.

    switch_to()出现在schedule()函数里面。调用形式switch_to(prev, next, last);
prev,next都是进程控制块task_struct的指针.prev指向当前运行的进程,next指向要切
换的进程.

    *  调用schedule()的时机

Direct invocation(直接调用)

    The scheduler is invoked directly when the current process must be blocked right away because the resource it needs is not available. In this case, the kernel routine that wants to block it proceeds as follows:
1. Inserts current in the proper wait queue.
2. Changes the state of current either to TASK_INTERRUPTIBLE or to TASK_UNINTERRUPTIBLE.
3. Invokes schedule( ).
4. Checks whether the resource is available; if not, goes to step 2.
5. Once the resource is available, removes current from the wait queue.

Lazy invocation(延迟调用)
    The scheduler can also be invoked in a lazy way by setting the TIF_NEED_RESCHED flag of current to 1. Because a check on the value of this flag is always made before resuming the execution of a User Mode process, schedule( ) will definitely be invoked at some time in the near future.
Typical examples of lazy invocation of the scheduler are:

    * When current has used up its quantum of CPU time; this is done by the scheduler_tick( ) function.
    * When a process is woken up and its priority is higher than that of the current process; this task is performed by the try_to_wake_up( ) function.
    * When a sched_setscheduler( ) system call is issued.

    * schedule()概述

    The act of picking the next task to run and switching to it is implemented via the schedule() function.选定下一个进程并切换到它去执行是通过schedule()函数实现的。
    The schedule() function is relatively simple for all it must accomplish. The following code determines the highest priority task:

struct task_struct *prev, *next;
struct list_head *queue;
struct prio_array *array;
int idx;

prev = current;
array = rq->active;
idx = sched_find_first_bit(array->bitmap);
queue = array->queue + idx;
next = list_entry(queue->next, struct task_struct, run_list);

    First, the active priority array is searched to find the first set bit. This bit corresponds to the highest priority task that is runnable. Next, the scheduler selects the first task in the list at that priority. This is the highest priority runnable task on the system and is the task the scheduler will run.
    首先,要在活动优先级数组中找到第一个被设置的位。该位对应着优先级最高的可执行进程。然后,调度程序选择这个级别链表里的头一个进程。这就是系统中优先级最高的可执行进程,也是马上会被调度执行的进程。

    If prev does not equal next, then a new task has been selected to run. The function context_switch() is called to switch from prev to next.
    如果prev和next不等,说明被选中的进程不是当前进程。此时函数context_switch()被调用,负责从prev切换到next.

    我刚才试了一下,在linux下死循环将阻塞整个系统,而ddk中死循环不会将windows完全阻塞掉,但系统运行很慢,这就是可抢先和不可抢先的区别吧?请大家确认一下!

再请教个刚才遇到的问题,在windows下由于driver中死循环,我不知如何退出driver,不得已reset机器,但重启后, windows仍然运行很慢,这是不是因为刚才的那个driver又自动加载的缘故?正规方法应如何处理这种情况?进入安全模式手工删除sys文件吗?

再就是,windows启动时是不是顺序加载每个驱动,如果发现新硬件,是不是直到你安装该硬件的驱动或取消安装该硬件的驱动后才继续加载另一个设备驱动?因为我发现如果不取消另一硬件的驱动安装(说明:我的机器上安了一个板子从来没有

装过驱动,所以每次开机时都提示发现新硬件,我一般都取消安装),那个死循环的driver就不会运行,一取消,系统立即慢了!请大家确认一下这个问题!

找到了!关于work item
引用:可以排队一个工作项(work item),之后这个工作项会请求回调驱动程序中的例程。回调将发生在PASSIVE_LEVEL级,在由操作系统所拥有的一个worker线程的上下文中运行。使用工作项(work item)可以避免自己创建仅偶尔醒来的线程的麻烦。
但我不明白如何用work item 实现schedule()的功能?
server.c

线程函数声明如下:

void thread(void)

创建线程如下:

int id;

int ret = pthread_create(&id,NULL,(void*)thread,NULL);

编译语句如下:

arm-linux-g++ server.c -ljrtp -lpthread -o server

错误提示:

ANSI C++ forbids implicit conversion from `void *\’ in argument passing

  解决:

int ret = pthread_create(&id,NULL,(void*(*)(void*)thread,NULL);

或者:(没有验证)

void *(*start_routine)(void*)就是需要的函数原型。
void* thread(void*)
&leftsign;
 …
&rightsign;
#include <stdio.h>
#include <pthread.h>
void * threadd(void *s)
&leftsign;
int i;
for(i=0;i<3;i++)
printf("This is a pthread.\\n");
&rightsign;

int main(void)
&leftsign;
pthread_t id;
int i,ret;
ret=pthread_create(&id,NULL,threadd,NULL);
if(ret!=0)&leftsign;
printf ("Create pthread error!\\n");
 return 1;

&rightsign;
for(i=0;i<3;i++)
printf("This is the main process.\\n");
pthread_join(id,NULL);
return (0);
&rightsign;

标签:, ,
20071009 Response ThreadAbortException - 六月 29, 2008 by yippee

20071009 Response ThreadAbortException
http://www.yippeesoft.com

Response.redirect和Response.End出现线程中止异常的处理
2005年08月06日 星期六 16:56

在调用response.end的时候有时会报告“线程正被终止”的异常,以下是微软官方的解决办法
症状
如果使用 Response.End、Response.Redirect 或 Server.Transfer 方法,则出现 ThreadAbortException 异常。 可使用 try-catch 语句捕捉此异常。
原因
Response.End 方法停止页的执行,并将该执行变换到应用程序的事件管线中的 Application_EndRequest 事件。 Response.End 后面的代码行将不执行。

此问题出现在 Response.Redirect 和 Server.Transfer 方法中,这是由于这两种方法都在内部调用 Response.End。
解决方案
若要解决此问题,请使用下列方法之一:

   * 对于 Response.End,调用 ApplicationInstance.CompleteRequest 方法而不调用 Response.End,以便跳过 Application_EndRequest 事件的代码执行。
   * 对于 Response.Redirect,使用重载 Response.Redirect(String url, bool endResponse),对 endResponse 参数它传递 false以取消对 Response.End 的内部调用。例如:

       Response.Redirect ("nextpage.aspx", false);

     如果使用这种解决方法,Response.Redirect 后面的代码将得到执行。
   * 对于 Server.Transfer,请改用 Server.Execute 方法。

状态
这种现象是设计使然。

由於使用 Response.End() 會觸發 System.Threading.ThreadAbortException 例外.
根據微軟文件建議改成 ApplicationInstance.CompleteRequest()
但改了之後, 發現 ApplicationInstance.CompleteRequest() 並不會中止 HTML RESPONSE
它仍繼續完整的把設計階段的網頁畫面送出.
即使我強制在它後面用 return 把程式結束掉, 它仍會繼續處理?

請問要如何解決呢?
目前您的問題的最佳解決方案仍是使用 Response.End(),
並利用 try… catch… 來決定如何處理 System.Threading.ThreadAbortException。

這個問題我從 1.x 一直注意到現在,甚至與微軟的專家們討論過,目前尚無更恰當的解決方案。
其中 ApplicationInstance.CompleteRequest() 的方式是無法解決您的問題的。

原來呼叫 Response.End() 就會丟出 ThreadAbortException.
害我以為是我程序出現錯誤了呢…

請 Google 幫忙一下,原來也有人碰到同樣情況:
Impersonation Failure : ASP.NET – ThreadAbortException
其實還不只是 Response.End(), Server.Transfer() 與 Response.Redirect() 也有機會發生此狀況,因為他們內部也呼叫了 Response.End().

比較正確的作法應該還是先呼叫

   Response.Flush();
   Response.Close();

會比較好些.

這是那篇文章所提供的參考資料:

   * http://support.microsoft.com/default.aspx?scid=kb;en-us;q312629
   * http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemwebhttpresponseclassredirecttopic2.asp
   * http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemwebhttpresponseclassendtopic.asp

症状
如果使用 Response.End、Response.Redirect 或 Server.Transfer 方法,则出现 ThreadAbortException 异常。 可使用 try-catch 语句捕捉此异常。
原因
Response.End 方法停止页的执行,并将该执行变换到应用程序的事件管线中的 Application_EndRequest 事件。 Response.End 后面的代码行将不执行。

此问题出现在 Response.Redirect 和 Server.Transfer 方法中,这是由于这两种方法都在内部调用 Response.End。
解决方案
若要解决此问题,请使用下列方法之一:

   * 对于 Response.End,调用 ApplicationInstance.CompleteRequest 方法而不调用 Response.End,以便跳过 Application_EndRequest 事件的代码执行。
   * 对于 Response.Redirect,使用重载 Response.Redirect(String url, bool endResponse),对 endResponse 参数它传递 false以取消对 Response.End 的内部调用。例如:

       Response.Redirect ("nextpage.aspx", false);

     如果使用这种解决方法,Response.Redirect 后面的代码将得到执行。
   * 对于 Server.Transfer,请改用 Server.Execute 方法。

状态
这种现象是设计使然。
这篇文章中的信息适用于:

   * Microsoft ASP .NET(包含在 .NET 框架中)

最近更新:     2002-1-17 (1.0)
关键字     kbDSupport kberror kbExceptHandling kbGrpDSASP kbprb kbWebForms KB312629

ASP教程:ASP内建对象Response    
      与   Request   是获取客户端   HTTP   信息相反   ,Response   对象是用来控制发送给用户的信息,包括直接发送信息给浏览器、重定向浏览器到另一个   URL   或设置   cookie   的值。    
      语法    
      Response.collection&line;property&line;method    
      一、属性    
      二、方法    
      1、Clear    
      可以用   Clear   方法清除缓冲区中的所有   HTML   输出。但   Clear   方法只清除响应正文而不清除响应标题。可以用该方法处理错误情况。但是如果没有将   Response.Buffer   设置为   TRUE,则该方法将导致运行时错误。    
      2、End    
      End   方法使   Web   服务器停止处理脚本并返回当前结果。文件中剩余的内容将不被处理。如果   Response.Buffer   已设置为   TRUE,则调用   Response.End   将缓冲输出。    

标签:
20070301 SiteAdvisor  CThreadPool - 八月 2, 2007 by yippee

20070301 SiteAdvisor  CThreadPool

http://www.yippeesoft.com

CNET科技资讯网报道 一家Web 过滤专业厂商推出了一项新服务,能够消除用户因使用搜索引擎而受到间谍件和广告件入侵的危险。

  ScanSafe推出一项新服务的试验版,向Google、雅虎等流行搜索引擎的搜索结果上添加标签,帮助用户识别恶意网站。

  名为Scandoo 的该服务能够实时地分析搜索结果,然后在“干净”网站的链接上添加一个绿色标记,并在可能的恶意网站链接后面显示一个虫子图片。

  搜索引擎不仅仅将用户引导到可信赖的网站,也会将用户引导到安装恶意软件或内容不恰当的网站。

  McAfee发布的一份报告显示,每个月,仅美国互联网用户就点击约2.85亿次的不安全链接。安全厂商也在试图解决这一问题。

  ScanSafe服务与McAfee的SiteAdvisor 类似。SiteAdvisor 要求用户安装相关软件,Scandoo 则要求用户在Scandoo 网站上输入搜索关键字。

  作为其新一代安全软件的一部分,赛门铁克也在开发一款与SiteAdvisor 类似的产品。

  据McAfee称,平均而言,搜索结果中3.1%的链接会带来危险。但是,在搜索“free screensavers ”(免费屏保)、“digital music ”(数字音乐)、“singers ”(歌手)等关键字时,这一比例可能上升至72%。

  ScanSafe 目前的合作伙伴为Google和MSN Search,未来数周内雅虎、Ask 也将成为其合作伙伴。

ScanSafe服务与McAfee的SiteAdvisor 类似。SiteAdvisor 要求用户安装相关软件,Scandoo 则要求用户在Scandoo 网站上输入搜索关键字。

McAfee SiteAdvisor(TM) Enterprise Beta

McAfee SiteAdvisor(TM) Enterprise Beta

McAfee SiteAdvisor Enterprise is a security add-on for Internet Explorer and Firefox browsers that help you identify sites that are linked to spyware, adware, spam, viruses, browser-based attacks, phishing, or online fraud.

Mcafee产品线越来越丰富,而且都是比较人性化的,Mcafee杀毒套装是一个挺不错产品,前期防护能

力据说是所有杀毒产品第一的(有好的前期防护能力,病毒就不能在你的机子里嚣张了).平时中毒很

多都是来自邮件浏览器等不小心点击到了什么鸟东西,最近Mcafee推出了一个浏览器插件对于各方

面防护有很好作用.

看看来自CB报道:

SiteAdvisor使你的电脑免于各种基于网络的攻击, 包括: 间谍软件、广告插件、垃圾邮件、病毒、

利用浏览器漏洞的攻击、钓鱼式攻击和身份欺骗等. 自动检测机制将不断地检查你所浏览的页

面、下载的文件和电子邮件. 当你在线搜索、浏览、认证的时候, SiteAdvisor的安全防护措施保证

你的安全.

McAfee SiteAdvisor(检测浏览页面安全)下载介绍:SiteAdvisor使你的电脑免于各种基于网络的攻击, 包括: 间谍软件、广告插件、LJ邮件、病毒、利用浏览器漏洞的攻击、钓鱼式攻击和身份欺骗等.自动检测机制将不断地检查你所浏览的页面、下载的文件和电子邮件. 当你在线搜索、浏览、认证的时候, SiteAdvisor的安全防护措施保证你的安全.

原来没有用过.Net中的ThreadPool,只是通过一些文章和帮助了解了一下,一直以为这是一个通用的线程池类,可以实例化多个线程池。今天经过再仔细看了Msdn并作了一些测试,才发现并不是这样的。

        ThreadPool是一个系统管理的线程池,每个进程只能有一个系统管理的线程池,ThreadPool不需要实例化,可以直接调用其中的静态方法进行操作,在Msdn中关于ThreadPool的概述已经说的比较清除,就不赘述了。

        那么在什么情况下使用ThreadPool比较好呢?阅读了一些朋友关于线程的心得体会后,结合自己的体验,对于.Net中线程池的使用,我有以下观点:

         1、线程池主要用于减少因频繁创建和销毁线程带来开销,因此那些经常使用且执行时间短的线程才需要用线程池来管理,用ThreadPool即可。

         2、执行时间较长而又不经常出现的任务,可以单独开辟线程处理,这类任务使用线程池并不会带来明显的性能提升,甚至有可能造成资源浪费。

         3、执行时间较长,但经常出现的任务,需要综合考虑具体执行的时间和出现频度,以及自己编写线程管理的复杂度来衡量;一般情况下,我认为单独开辟线程就好。

         4、实际作项目时,别忘了不同的机器,性能不一样,多线程处理能力也是不一样的。

         以上只是一些粗浅的观点,有不对之处欢迎讨论和指正。
线程池
MFC 7.0线程池是基于NT I/O Completion Port。CThreadPool是一个支持工作线程的模板类。
当一个线程可以工作时,你的工作线程的执行函数会被调用。工作线程的查询和执行遵循FIFO(先入先
出)原则。使用线程池必须:

·一次一个线程地初始化

·逐一执行在请求队列中的线程

·一次一个线程地销毁

·在工作线程类中声明一个RequestType typedef,它会在执行时被处理

RequestType是一个不透明的类型,不能大于sizeof(ULONG_PTR)(即,x86 PC上的32位),所以你不可以
使用类的实例或大的原始类型(如浮点)。
下面是一个示例:

class CMyWorker
&leftsign;
    public:
    typedef CMyData*    RequestType;
    BOOL Initialize( void* initParam );
    void Execute( CMyData* request, void* initParam, OVERLAPPED* pOverlapped );
    void Terminate( void* initParam );
&rightsign;;

下面是怎样在线程池初始化和查询一个任务:

CThreadPool< CMyWorker >    threadPool;

threadPool.Initialize();
threadPool.QueueRequest( new CMyData());
threadPool.Shutdown( 1000L );

标签:
20070102  InternetOpen thread timerout - 六月 5, 2007 by yippee

070102  InternetOpen thread timerout

如何通过创建另一个线程控制连接超时值
How To Control Connection Timeout Value by Creating Second Thread
SUMMARY
This acticle shows a workaround to the InternetSetOption API bug on setting timeout values by creating a second thread. For information about the bug, please see the following article in the Microsoft Knowledge Base:
176420 (http://support.microsoft.com/kb/176420/EN-US/) InternetSetOption Does Not Set Timeout Values
MORE INFORMATION
The following sample code controls how long to wait while connecting to the FTP server in WinInet. It creates a worker thread to call the blocking WinInet APIs. If the connection takes more time than the specified timeout value, the original thread will call InternetCloseHandle to release the blocking WinInet function. For HTTP communications the same idea applies. In the case of HTTP, the actual connection occurs in the call to HttpSendRequest.

要对设置超值 InternetSetOption API 错误由创建另一个线程此 acticle 显示解决。 有关错误, 请参见下列文章 Microsoft 知识库文章:
176420 (http://support.microsoft.com/kb/176420/EN-US/) InternetSetOption 不设置超时值

要连接到 FTP 服务器 WinInet 中时等待时间以下示例代码控件。 创建辅助线程以调用阻塞 WinInet API。 如果该连接所花的时间比指定超值, 原始线程将调用 InternetCloseHandle 来释放阻塞 WinInet 函数。 对于 HTTP 通讯应用同一思路。 万一有 HTTP, 实际连接发生在 HttpSendRequest 调用。    #include <windows.h>
   #include <wininet.h>
   #include <iostream.h>

   DWORD WINAPI WorkerFunction( LPVOID );
   HINTERNET g_hOpen, g_hConnect;

   typedef struct
   &leftsign;
       CHAR* pHost;
       CHAR* pUser;
       CHAR* pPass;
   &rightsign; PARM;

   void main()
   &leftsign;
       CHAR    szHost[] = "localhost";
       CHAR    szUser[] = "JoeB";
       CHAR    szPass[] = "test";
       CHAR    szLocalFile[] = "localfile";
       CHAR    szRemoteFile[] = "remotefile";
       DWORD   dwExitCode;
       DWORD   dwTimeout;
       PARM    threadParm;

       g_hOpen = 0;
       if ( !( g_hOpen = InternetOpen ( "FTP sample",
                                        LOCAL_INTERNET_ACCESS,
                                        NULL,
                                        0,
                                        0 ) ) )
       &leftsign;        
           cerr << "Error on InternetOpen: " << GetLastError() << endl;
           return ;
       &rightsign;

       // Create a worker thread
       HANDLE   hThread;
       DWORD    dwThreadID;
       threadParm.pHost = szHost;
       threadParm.pUser = szUser;
       threadParm.pPass = szPass;

       hThread = CreateThread(
                     NULL,            // Pointer to thread security attributes
                     0,               // Initial thread stack size, in bytes
                     WorkerFunction,  // Pointer to thread function
                     &threadParm,     // The argument for the new thread
                     0,               // Creation flags
                     &dwThreadID      // Pointer to returned thread identifier
                 );   

       // Wait for the call to InternetConnect in worker function to complete
       dwTimeout = 5000; // in milliseconds
       if ( WaitForSingleObject ( hThread, dwTimeout ) == WAIT_TIMEOUT )
       &leftsign;
           cout << "Can not connect to server in "
                << dwTimeout << " milliseconds" << endl;
           if ( g_hOpen )
   InternetCloseHandle ( g_hOpen );
           // Wait until the worker thread exits
           WaitForSingleObject ( hThread, INFINITE );
           cout << "Thread has exited" << endl;
           return ;
       &rightsign;
   
       // The state of the specified object (thread) is signaled
       dwExitCode = 0;
       if ( !GetExitCodeThread( hThread, &dwExitCode ) )
       &leftsign;
           cerr << "Error on GetExitCodeThread: " << GetLastError() << endl;
           return ;
       &rightsign;

       CloseHandle (hThread);
       if ( dwExitCode )
       // Worker function failed
          return ;
   
       if ( !FtpGetFile ( g_hConnect,
                          szRemoteFile,
                          szLocalFile,
                          FALSE,INTERNET_FLAG_RELOAD,
                          FTP_TRANSFER_TYPE_ASCII,
                          0 ) )
       &leftsign;
           cerr << "Error on FtpGetFile: " << GetLastError() << endl;
           return ;
       &rightsign;

       if ( g_hConnect )
           InternetCloseHandle( g_hConnect );
       if ( g_hOpen )
           InternetCloseHandle( g_hOpen );

       return ;
   &rightsign;

   /////////////////// WorkerFunction //////////////////////
   DWORD WINAPI
   WorkerFunction(
       IN LPVOID vThreadParm
   )
   /*
   Purpose:
       Call InternetConnect to establish a FTP session 
   Arguments:
       vThreadParm – points to PARM passed to thread
   Returns:
       returns 0 
   */
   &leftsign;
       PARM* pThreadParm;
       // Initialize local pointer to void pointer passed to thread
       pThreadParm = (PARM*)vThreadParm;
       g_hConnect = 0;
   
       if ( !( g_hConnect = InternetConnect (
                                g_hOpen,
                                pThreadParm->pHost,
                                INTERNET_INVALID_PORT_NUMBER,
                                pThreadParm->pUser,
pThreadParm->pPass,
                                INTERNET_SERVICE_FTP,
                                0,
                                0 ) ) )
       &leftsign;
           cerr << "Error on InternetConnnect: " << GetLastError() << endl;
           return 1; // failure
       &rightsign;
      
       return 0;  // success
   &rightsign;

标签:, , , ,

0526 intel 双核 超线程 DualCore HyperThreading - 十一月 8, 2006 by yippee

0526 intel 双核 超线程 DualCore HyperThreading

最近发现WINXP机器启动慢了许多,并且是不是运行中出现假死,找找资料
Intel Delivers Hyper-Threading Technology With Pentium® 4 Processor 3 Ghz Milestone
Intel称其双核CPU为Double Core;而AMD则称为Dual Core。两者都是单模组上的双核设计,但最大的不同是AMD双核能相互通信,
intel双核技术与超线程技术的区别作者:麦田守望者 提交时间:2006-5-10 8:22:56[推荐给好友]
 超线程技术已经不是什么新鲜事物了,但普通用户可能与双核心技术区分不开。例如开启了超线程技术的Pentium 4 630与Pentium D 820在操作系统中都同样被识别为两颗处理器,它们究竟是不是一样的呢?这个问题确实具有迷惑性。  其实,可以简单地把双核心技术理解为两个"物理"处理器,是一种"硬"的方式;而超线程技术只是两个"逻辑"处理器,是一种"软"的方式。   从原理上来说,超线程技术属于Intel版本的多线程技术。这种技术可以让单CPU拥有处理多线程的能力,而物理上只使用一个处理器。超线程技术为每个物理处理器设置了两个入口-AS(Architecture State,架构状态)接口,从而使操作系统等软件将其识别为两个逻辑处理器。   这两个逻辑处理器像传统处理器一样,都有独立的IA-32架构,它们可以分别进入暂停、中断状态,或直接执行特殊线程,并且每个逻辑处理器都拥有APIC(Advanced Programmable Interrupt Controller,高级可编程中断控制器)。虽然支持超线程的Pentium 4能同时执行两个线程,但不同于传统的双处理器平台或双内核处理器,超线程中的两个逻辑处理器并没有独立的执行单元、整数单元、寄存器甚至缓存等等资源。它们在运行过程中仍需要共用执行单元、缓存和系统总线接口。在执行多线程时两个逻辑处理器均是交替工作,如果两个线程都同时需要某一个资源时,其中一个要暂停并要让出资源,要待那些资源闲置时才能继续。因此,超线程技术所带来的性能提升远不能等同于两个相同时钟频率处理器带来的性能提升。可以说Intel的超线程技术仅可以看做是对单个处理器运算资源的优化利用。   而双核心技术则是通过"硬"的物理核心实现多线程工作:每个核心拥有独立的指令集、执行单元,与超线程中所采用的模拟共享机制完全不一样。在操作系统看来,它是实实在在的双处理器,可以同时执行多项任务,能让处理器资源真正实现并行处理模式,其效率和性能提升要比超线程技术要高得多,不可同日而语。简单来说:“双核”指的是物理双核“超线程”指的是逻辑双核

超线程技术就是利用特殊的硬件指令,把两个逻辑内核模拟成两个物理芯片,让单个处理器都能使用线程级并行计算,进而兼容多线程操作系统和软件,减少了CPU的闲置时间,提高的CPU的运行效率。因此支持Intel超线程技术的cpu,打开超线程设置,允许超线程运行后,在操作系统中看到的cpu数量是实际物理cpu数量的两倍,就是1个cpu可以看到两个,两个可以看到四个。 有超线程技术的CPU需要芯片组、软件支持,才能比较理想的发挥该项技术的优势。
什么是双核处理器呢?双核处理器背后的概念蕴涵着什么意义呢?简而言之,双核处理器即是基于单个半导体的一个处理器上拥有两个一样功能的处理器核心。换句话说,将两个物理处理器核心整合入一个核中。企业IT管理者们也一直坚持寻求增进性能而不用提高实际硬件覆盖区的方法。多核处理器解决方案针对这些需求,提供更强的性能而不需要增大能量或实际空间。 双核心处理器技术的引入是提高处理器性能的有效方法。因为处理器实际性能是处理器在每个时钟周期内所能处理器指令数的总量,因此增加一个内核,处理器每个时钟周期内可执行的单元数将增加一倍。在这里我们必须强调一点的是,如果你想让系统达到最大性能,你必须充分利用两个内核中的所有可执行单元:即让所有执行单元都有活可干! 为什么IBM、HP等厂商的双核产品无法实现普及呢,因为它们相当昂贵的,从来没得到广泛应用。比如拥有128MB L3缓存的双核心IBM Power4处理器的尺寸为115×115mm,生产成本相当高。因此,我们不能将IBM Power4和HP PA8800之类双核心处理器称为AMD即将发布的双核心处理器的前辈。 目前,x86双核处理器的应用环境已经颇为成熟,大多数操作系统已经支持并行处理,目前大多数新或即将发布的应用软件都对并行技术提供了支持,因此双核处理器一旦上市,系统性能的提升将能得到迅速的提升。因此,目前整个软件市场其实已经为多核心处理器架构提供了充分的准备。CPU生产商为了提高CPU的性能,通常做法是提高CPU的时钟频率和增加缓存容量。不过目前CPU的频率越来越快,如果再通过提升CPU频率和增加缓存的方法来提高性能,往往会受到制造工艺上的限制以及成本过高的制约。

尽管提高CPU的时钟频率和增加缓存容量后的确可以改善性能,但这样的CPU性能提高在技术上存在较大的难度。实际上在应用中基于很多原因,CPU的执行单元都没有被充分使用 。如果CPU不能正常读取数据(总线/内存的瓶颈),其执行单元利用率会明显下降。另外就是目前大多数执行线程缺乏ILP(Instruction-Level Parallelism,多种指令同时执行)支持。这些都造成了目前CPU的性能没有得到全部的发挥。因此,Intel则采用另一个思路去提高CPU的性能,让CPU可以同时执行多重线程,就能够让CPU发挥更大效率,即所谓“超线程(Hyper-Threading,简称“HT”)”技术。超线程技术就是利用特殊的硬件指令,把两个逻辑内核模拟成两个物理芯片,让单个处理器都能使用线程级并行计算,进而兼容多线程操作系统和软件,减少了CPU的闲置时间,提高的CPU的运行效率。 采用超线程及时可在同一时间里,应用程序可以使用芯片的不同部分。虽然单线程芯片每秒钟能够处理成千上万条指令,但是在任一时刻只能够对一条指令进行操作。而超线程技术可以使芯片同时进行多线程处理,使芯片性能得到提升。 超线程技术是在一颗CPU同时执行多个程序而共同分享一颗CPU内的资源,理论上要像两颗CPU一样在同一时间执行两个线程,P4处理器需要多加入一个Logical CPU Pointer(逻辑处理单元)。因此新一代的P4 HT的die的面积比以往的P4增大了5%。而其余部分如ALU(整数运算单元)、FPU(浮点运算单元)、L2 Cache(二级缓存)则保持不变,这些部分是被分享的。 虽然采用超线程技术能同时执行两个线程,但它并不象两个真正的CPU那样,每各CPU都具有独立的资源。当两个线程都同时需要某一个资源时,其中一个要暂时停止,并让出资源,直到这些资源闲置后才能继续。因此超线程的性能并不等于两颗CPU的性能。 英特尔P4 超线程有两个运行模式,Single Task Mode(单任务模式)及Multi Task Mode(多任务模式),当程序不支持Multi-Processing(多处理器作业)时,系统会停止其中一个逻辑CPU的运行,把资源集中于单个逻辑CPU中,让单线程程序不会因其中一个逻辑CPU闲置而减低性能,但由于被停止运行的逻辑CPU还是会等待工作,占用一定的资源,因此Hyper-Threading CPU运行Single Task Mode程序模式时,有可能达不到不带超线程功能的CPU性能,但性能差距不会太大。也就是说,当运行单线程运用软件时,超线程技术甚至会降低系统性能,尤其在多线程操作系统运行单线程软件时容易出现此问题。 需要注意的是,含有超线程技术的CPU需要芯片组、软件支持,才能比较理想的发挥该项技术的优势。目前支持超线程技术的芯片组包括如:英特尔i845GE、PE及矽统iSR658 RDRAM、SiS645DX、SiS651可直接支持超线程;英特尔i845E、i850E通过升级BIOS后可支持;威盛P4X400、P4X400A可支持,但未获得正式授权。操作系统如:Microsoft Windows XP、Microsoft Windows 2003,Linux kernel 2.4.x以后的版本也支持超线程技术。

标签:, ,
0403  _beginthreadex _endthreadex 线程 THREADEX.C - 八月 24, 2006 by yippee

04030 _beginthreadex _endthreadex 线程 THREADEX.C

今天一个同事任务单留言,觉得我开启线程后没有END,有点管杀不管埋的意思。
我倒是觉得代码没有问题,因为以前有看过,现在重新记录一下。

看看源代码 VS6\\VC98\\CRT\\SRC\\THREADEX.C
*threadex.c – Extended versions of Begin (Create) and End (Exit) a Thread
*
*       Copyright (c) 1989-1997, Microsoft Corporation. All rights reserved.
*
*Purpose:
*       This source contains the _beginthreadex() and _endthreadex()
*       routines which are used to start and terminate a thread.  These
*       routines are more like the Win32 APIs CreateThread() and ExitThread()
*       than the original functions _beginthread() & _endthread() were.

*_beginthreadex() – Create a child thread
      /*         * Create the new thread using the parameters supplied by the caller.         */
        if ( (thdl = (unsigned long)              CreateThread( security,                            stacksize,                            _threadstartex,                            (LPVOID)ptd,                            createflag,                            thrdaddr))

*_threadstartex() – New thread begins here
/*         * Guard call to user code with a _try – _except statement to
         * implement runtime errors and signal support         */
        __try &leftsign;
                _endthreadex (
                    ( (unsigned (WINAPI *)(void *))(((_ptiddata)ptd)->_initaddr) )
                    ( ((_ptiddata)ptd)->_initarg ) ) ;
        &rightsign;

*_endthreadex() – Terminate the calling thread
         * Free up the _tiddata structure & its subordinate buffers
         *      _freeptd() will also clear the value for this thread
         *      of the TLS variable __tlsindex.

*       Differences between _beginthread/_endthread and the "ex" versions:
*
*         1)  _beginthreadex takes the 3 extra parameters to CreateThread
*             which are lacking in _beginthread():
*               A) security descriptor for the new thread
*               B) initial thread state (running/asleep)
*               C) pointer to return ID of newly created thread
*
*         2)  The routine passed to _beginthread() must be __cdecl and has
*             no return code, but the routine passed to _beginthreadex()
*             must be __stdcall and returns a thread exit code.  _endthread
*             likewise takes no parameter and calls ExitThread() with a
*             parameter of zero, but _endthreadex() takes a parameter as
*             thread exit code.
*
*         3)  _endthread implicitly closes the handle to the thread, but
*             _endthreadex does not!
*
*         4)  _beginthread returns -1 for failure, _beginthreadex returns
*             0 for failure (just like CreateThread).

http://www.yippeesoft.com/blog/p/04030beginthreadexendq.php

04030 _beginthreadex _endthreadex 线程 问题

标签:, , ,
04030 _beginthreadex _endthreadex 线程 问题 - 八月 22, 2006 by yippee

04030 _beginthreadex _endthreadex 线程 问题

今天一个同事任务单留言,觉得我开启线程后没有END,有点管杀不管埋的意思。
我倒是觉得代码没有问题,因为以前有看过,现在重新记录一下。

启动
hthread = (HANDLE)_beginthreadex(0, 0, Thread, NULL,
  CREATE_SUSPENDED, &threadId);

线程
while (p ->b ==1)
 &leftsign;
  do();
 &rightsign;
 psip->b=2;
 TRACE("Thread out \\r\\n");
 return 0;

关闭
for (int i=0;i<10;i++)
 &leftsign;
  b=0;
  OSSleep(100);
  if (b==2)
   break;
 &rightsign;
 if (h!=NULL)
 &leftsign;
  TerminateThread(h,0);
 &rightsign;
 b=0;

关于_beginthreadex与_endthreadex的问题

在线程函数中,要不要调用_endthreadex来释放堆中内存空间及ExitThread?

如果调用该函数的话,在线程函数中的局部对象将不能得到正常的析构.如果不调用这个函数,无法释放与线程相关的_tiddata结构体. 请高手指点.

_beginthreadex会自动调用_endthreadex
最好在线程函数中不要调用_endthreadex()函数,
最安全的方式是让线程函数自然的return,如果在线程函数中调用了_endthreadex函数的话,线程就会在调用_endthreadex函数调用的地方立即退出,不回继续向下执行,导致在线程局部存储空间中的局部对象或者变量的析构函数不会被调用,有可能导致资源的泄漏!

Jeffrey Richter 给出的一些注解:
first, if you call _beginthreadex, you\’ll get back a handle to the thread. At some point, that thread\’s handle must be closed. _endthreadex **doesn\’t** do it. Normally, the thread that called _beginthreadex (possibly the main thread) will call CloseHandle on the newly created thread\’s handle when the thread handle is no longer needed. Second, you only need to use _beginthreadex if your app uses CRT functions. If it doesn\’t, then you can just use CreateThread. Also, you can use CreateThread if only one thread (the main thread) in your app uses the CRT. If newly created threads don\’t use the CRT, you don\’t need _beginthreadex or the multithreaded CRT.

Windows平台的线程同步机制小结  深入浅出Win32多线程程序设计之线程通信  VC中利用多线程技术实现线程之间的通信  Windows 95 下 多 线 程 编 程 技术 及 其 实 现  多线程编程

标签:, , , ,
0303 dos 控制台 beginthreadex waveinout - 六月 29, 2006 by yippee

0303 dos 控制台 beginthreadex waveinout

首先是头文件问题:
syntax error : missing \’;\’ before identifier \’MMVERSION\’

跟着进去一看
#ifdef _WIN32
typedef UINT        MMVERSION;  /* major (high byte), minor (low byte) */

然后我就自作聪明加上DEFINE,结果仍然不行,看看MSDN

Windows NT/2000/XP: Included in Windows NT 3.1 and later.
  Windows 95/98/Me: Included in Windows 95 and later.
  Header: Declared in Mmsystem.h; include Windows.h.
  Library: Use Winmm.lib.
  Unicode: Implemented as Unicode and ANSI versions on Windows NT/2000/XP. Also supported by Microsoft Layer for Unicode

加上,OK
#include <windows.h>

然后就是这个函数
 error C2065: \’_beginthreadex\’ : undeclared identifier

 看看定义:也OK
 _CRTIMP unsigned long __cdecl _beginthreadex(void *, unsigned,
        unsigned (__stdcall *) (void *), void *, unsigned, unsigned *);

刚开始还以为是DOS控制台程序不能多线程,后来想想还是在WINDOWS 下面,应该没有问题的
应该是多线程设置问题

 vc project/settings 把默认命令行“/MLd”修改为:“/MTd”

 c/c++ === code genneration === use run-time libary == debug multithreaded dll

 Project->Settings->click C/C++ tab,
在Category 中选Code Generation, 然后在Use run-time libray 中选一个
Multithread 配置

To use _beginthread or _beginthreadex,
the application must link with one of the multithreaded C run-time libraries.

project->setting->c/c++标签->选code generation->选multithreaded dll

Q:Why do I get an unresolved external (LNK2001) error on _beginthreadex and _endthreadex? (top)

A:This happens when you compile a project that uses MFC, but your compiler settings are set to use the single-threaded version of the C runtime library (CRT). Since MFC uses threads, it requires the multithreaded CRT. Since the single-threaded CRT doesn\’t contain _beginthreadex() and _endthreadex(), you get a linker error on those two functions.

To change your CRT setting, click Project->Settings and go to the C/C++ tab. Set the Category combo box to Code Generation. In the Use run-time library combo box, chose one of the multithreaded versions of the CRT. For debug builds, choose Debug Multithreaded or Debug Multithreaded DLL. For release builds, choose Multithreaded or Multithreaded DLL. The versions that say "DLL" use MSVCRT.DLL, while the others do not depend on that DLL.

结果可以调试了,但是总是刚刚进入断点就整个程序退出了,迷糊了一下,马上加上
WHILE(1);

OK
 error C2065: \’printf\’ : undeclared identifier

标签:, ,