8.23敏视笔试题

1.写出string的构造函数,析构函数

class string 
{
   public:
    string(const char*str=NULL);
    ~string();
    string(const string&another);
    string&operator=(const string&rhs);
    private:
    char*m_data;
}
    string::string(const char*str=NULL)
    {
        if(m_data==NULL)
        {
           m_data=new char[1];
            *m_data='\0';
        }
        else
        {
            m_data=new char[strlen(str)+1];
            strcpy(m_data,str);

        }
    }
    string::string(const string&another)
    {
         if(this==&another)
                return *this;
           else
            {
                delete m_data;
                m_data=new char[string(another.m_data)+1];
                strcpy(m_data,another.m_data);
                return *this;
        
            }

    }
    string::~string()
    {

        if(m_data!=NULL)
        {
            delete m_data;
        
            m_data=NULL;    
        }

    }

2.设计两个线程通信

      一个线程发送数据包,另一个线程读取数据包,下面是接收数据包的线程的工作函数

        

#include <pthread.h>

pthread_mutex_t mutex
pthread_cond_t cond
volatile unsigned int *buffer=NULL;
volatile unsigned int *id=NULL;
volatile unsigned in *size=NULL;    

void *handle1(void*arg)
   {
            
        pthread_mutex_lock(&mutex);
        
        while(*buffer==0)
        {
        
        pthread_cond_wait(&cond,&mutex);

        }
        
        BUFFER_getPacket(&id,&buffer,&size);

        pthread_mutex_unlock(&mutex);

        return void*1;


    }

发送数据包线程的

 

#include <ptherad.h>

void*handler2(void*arg)
 {

    pthread_mutex_lock(&mutex);

    if(*buffer==0)
    {
    Get_packet(id,&buffer,size);
    pthread_cond_signal(&cond);

    }
    
    pthread_mutex_unlock(&mutex);
 }

3.谈一下linux系统调用的原理

1.简单的来说,是操作系统提供给用户空间的一组特殊接口。用户程序通过这组特殊的接口来获得操作系统提供内核的特殊服务,它把用户的请求传递到内核,待内核把请求处理完后,再把处理结果送给用户空间,(用户进程想要获得系统服务)

2.系统调用的实现利用了x86的软件中断,通过软件指令触发,跟嵌入式操作系统中的软中断有很大区别。

系统调用的参数通过eax,ebx,ecx等寄存器来存放这些参数

  • 系统调用其实很简单,就是所以操作系统的API都是通过软件的中断动态的调用,通过调用int $0x80 触发软件中断,然后通过一些寄存器将参数传入,实现对操作系统API的调用。

        

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值