智能家居实训第四天 多线程

================线程========================
在单个程序中同时运行多个线程完成不同的工作,称为多线程。

1.线程的创建  pthread_create
  #include

  int pthread_create(pthread_t *thread, const pthread_attr_t *attr,
                          void *(*start_routine) (void *), void *arg);
    返回值:成功   返回一个0
            失败   返回 指针或者错误码
    
    参数:pthread_t *thread                 线程的识别号
          const pthread_attr_t *attr        线程的属性,一般设置NULL
          void *(*start_routine)(void *)    线程实现的函数  void()
          void *arg                         线程函数的参数 一般设置为NULL
     例子: 常规 get_x_y(&x,&y);
              get_x_y(),(&x,&y)

2.线程的退出:pthread_exit
   #include

   void pthread_exit(void *retval);
     参数:void *retval      线程退出时候的值
     
3.回收线程:pthread_join
    #include

    int pthread_join(pthread_t thread, void **retval);
    返回值:成功  返回 0
            失败  返回 错误码
    参数:pthread_t thread      线程的识别号       
          void **retval         线程的返回值  NULL         

==================linux当中的时间编程============
1.获取系统时间格式 time()
   #include

   time_t time(time_t *tloc);
         参数:time_t *tloc
                ----》将获取到的系统时间存储到该变量中
    将time函数获取的时间转化为大家熟悉格式(年月日时分秒)
2.获取系统时间   ctime()
  #include
  char *ctime(const time_t *timep);
    返回值:成功 返回一个数
            失败 返回 -1 或者 NULL
    参数: const time_t *timep

  struct tm
  {
     int tm_sec;      /*seconds*/   秒  
     int tm_min;      /*minures*/   分
     int tm_hour;     /*hours*/     时
     int tm_mday;     /*day*/       天
     int tm_mon;      /*month*/     月
     int tm_year;     /*year*/      年
     int tm_wday;     /*day of week*/   星期 
     int tm_yday;     /*day in the year */ 统计天数
     int tm_isdst;    /*daylight saving time */ 时令
  };

 字符串拼接:sprintf
  #include

  int sprintf(char *str, const char *format, ...);
  变参函数
      参数:char *str          字符串储存空间
            const char *format  字符串链接格式
编译错误:
 /tmp/ccxQmifu.o: In function `main':
pthread.c:(.text+0xfa): undefined reference to `pthread_create'
pthread.c:(.text+0x138): undefined reference to `pthread_join'
collect2: ld returned 1 exit status
解决办法:
链接库:-l 
   本地编译:gcc pthread.c -o pthread -lpthread
   arm开发板:arm-linux-gcc pthread.c -o pthread -lpthread

==================电子相册=================
1.欢迎界面一张,主界面一张,手动翻页一张,自动翻页一张
2.要求:2.1欢迎界面延时5秒显示主界面
        2.2主界面有两个子菜单:分别为手动和自动(4张图)
        2.3子菜单都要能返回主界面
        2.4在主界面实时显示时间  man 3 gmtime  localtime


github源代码
     
     
 

你可能感兴趣的:(嵌入式智能家居实训)