`
vearne
  • 浏览: 18238 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论
文章列表
此博客即将废弃,所有内容将迁往CSDN 以下是新地址 http://blog.csdn.net/woshiaotian   博客有了新站 http://vearne.cc/
 注意:消息是由主线程产生的,而消息这时候在堆中,两个线程通过全局变量获取访问消息。 #include <pthread.h> #include <stdlib.h> #include <stdio.h> struct msg { int data; struct msg *m_next; /* ... more stuff here ... */ }; struct msg *workq; pthread_cond_t qready = PTHREAD_COND_INITIALIZER; pthread_mutex_ ...
注意:消息是由主线程产生的,而消息这时候在栈中,两个线程通过全局变量获取访问消息。Unix环境高级编程P288进程的所有信息对该进程的所有线程都是共享的,包括可执行的程序文本、程序的全局变量和堆内存、栈以及文件描述符。   #include <pthread.h> #include <stdio.h> struct msg { int data; struct msg *m_next; /* ... more stuff here ... */ }; struct msg *workq; pthread_cond_t qready ...
非常好的参考资料 1.HTTP 协议资料 http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.2 2.使用telnet模拟浏览器访问网页 http://pcwanli.blog.163.com/blog/static/4531561120091115105240732/     #include "apue.h" #include <netdb.h> #include <errno.h> #include <sys/socket.h> #includ ...

重复删除指针

#include <iostream> using namespace std; class Base{ public: void f(){ cout<<"base"<<endl; } private: int a; }; int main(){ Base* b = new Base; delete b; delete b; return 0; }  经过试验表明重复删除会导致运行时报错,但如果加上b = NULL;第二次delete操作将不会执行,程序可以正常执行。
#include <iostream> using namespace std; class Base{ public: void f(){ cout<<"base"<<endl; } }; class Derived:public Base{ public: void f(){ cout<<"derived"<<endl; } }; int main(){ Base b; Derived d; b = d; b.f(); d. ...
请参考linux c一站式学习,此节内容 http://learn.akae.cn/media/ch30s03.html#id2867242 可以设置父进程忽略SIGCHLD信号,或者在SIGCHLD信号的处理函数中调用wait函数,即可获取子进程的退出状态,且销毁僵尸进程。 1)调用wait函数   #include <unistd.h> #include <stdlib.h> #include <iostream> #include <signal.h> #include <sys/wait.h> using n ...
  #include <iostream> using namespace std; class based{ public: based(){ } ~based(){ cout<<"flag 1"<<endl; } virtual void f(){ cout<<"ok1"<<endl; } }; class derived:public based{ public: ~derived(){ cout<<"f ...
  #include <iostream> #include <stack> using namespace std; struct node{ int data; struct node* lchild; struct node* rchild; }; typedef struct node Node; void inOrderTraverse(Node* root){ Node* p = root; stack<Node*> s; while(p||!s.empty()){ if(p){ s.push(p); ...
#include <iostream> using namespace std; int get_median(int a[],int begin1,int end1,int b[],int begin2,int end2,int k){ if(begin1>end1){ //在数组A中无法找到 return get_median(b,begin2,end2,a,begin1,end1,k); } int t = (begin1+end1)/2; if(a[t]>=b[k-t-1]&&a[t]<=b[k-t]){//g ...
  #include <iostream> using namespace std; class smart_count{ private: int use_count; public: smart_count(int c=0):use_count(c){ } ~smart_count(){} int addref(){ return ++use_count; } int release(){ return --use_count; } }; template<class T> class smart_pt ...
#include <iostream> using namespace std; template<int m,int n> void print(int a[m][n]){ for(int i=0;i<m;i++){ for(int j=0;j<n;j++){ cout<<a[i][j]<<" "; } } cout<<endl; } int main(){ int a[][3]={{1,2,3},{4,5,6}}; print<2 ...
#include <iostream> #include <queue> #include <algorithm> #include <stack> using namespace std; int a[5][5]={{0,1,0,1,0},{1,0,1,0,1},{0,1,0,1,1},{1,0,1,0,0},{1,0,1,0,0}}; template<int n> void bfs(int i){ queue<int> q; bool flag[n]; memset(flag,false ...

堆排序代码实现

  void heap_adjust(int a[],int i,int size){ int temp; int j = i*2 +1; if(i<=size/2-1){ //保证其为非叶子节点----这里请注意 if(j+1<size&&a[j]<a[j+1]){ //找出子节点中值最大的 j++; } if(a[i]<a[j]){ temp = a[i]; a[i] = a[j]; a[j] = temp; heap_adjust(a,j,size); } ...
java中的匿名类除了还有两种有趣的用法   /** * TODO Comment of AnonymousTest * * @author aotian.zhuw */ class EntryInterface { public void print() { System.out.println("hello world"); } } public class AnonymousTest { private EntryInterface a; public void ...
Global site tag (gtag.js) - Google Analytics