std::async使用

/*
 * @Author: Mrnothing
 * @Date: 2021-06-18 14:36:14
 * @LastEditTime: 2021-06-18 15:28:33
 * @LastEditors: Mrnothing
 * @Description: 
 * @FilePath: \asyncc:\Users\Mrnothing\DOCUME~1\MobaXterm\slash\RemoteFiles\460430_2_99\main.cpp
 * Copyright (c) 2020 KEDACOM.Co.Ltd All rights reserved
 */
#include <future>
#include <iostream>
// #include <stout/stringify.hpp>
// #include <stout/stringify.hpp>
#include "arm_neon.h"
#include <stdint.h>
#include <sys/time.h>

static unsigned int get_current_time(void)
{
	struct timeval tv;
	gettimeofday(&tv, NULL);
	return tv.tv_sec * 1000 + tv.tv_usec / 1000;
}



int function1(unsigned char *pu8srcimg, unsigned char *pu8dstimg, int s32Height, int s32Width)
{
  int n = 100000;
  while(n--)
  {
    uint32_t T1 = get_current_time();
    RGBHWC2RGBCHW_q(pu8srcimg, pu8dstimg, s32Height, s32Width);
    uint32_t T2 = get_current_time();
    // printf(" fun1 time:%dms \n",T2-T1);
  }
  return 0;
}

int function2(unsigned char *pu8srcimg, unsigned char *pu8dstimg, int s32Height, int s32Width)
{
  int n = 100000;
  while(n--)
  {
    uint32_t T1 = get_current_time();
    RGBHWC2RGBCHW(pu8srcimg, pu8dstimg, s32Height, s32Width);
    uint32_t T2 = get_current_time();
    printf(" fun2 time:%dms \n",T2-T1);
  }
  return 0;
}


int main()
{

  uint32_t u32W = 4096;
  uint32_t u32H = 2176;
  uint8_t *pu8src = (uint8_t *)calloc(1, sizeof(uint8_t)*u32W*u32H*3);
  uint8_t *pu8dst = (uint8_t *)calloc(1, sizeof(uint8_t)*u32W*u32H*3);

  uint8_t *pu8src1 = (uint8_t *)calloc(1, sizeof(uint8_t)*u32W*u32H*3);
  uint8_t *pu8dst1 = (uint8_t *)calloc(1, sizeof(uint8_t)*u32W*u32H*3);

  uint8_t *pu8src2 = (uint8_t *)calloc(1, sizeof(uint8_t)*u32W*u32H*3);
  uint8_t *pu8dst2 = (uint8_t *)calloc(1, sizeof(uint8_t)*u32W*u32H*3);

  uint8_t *pu8src3 = (uint8_t *)calloc(1, sizeof(uint8_t)*u32W*u32H*3);
  uint8_t *pu8dst3 = (uint8_t *)calloc(1, sizeof(uint8_t)*u32W*u32H*3);

  uint32_t T1 = get_current_time();

  std::future<int> Fun0 = std::async(function1, pu8src, pu8dst, u32H, u32W);
  std::future<int> Fun1 = std::async(function2, pu8src1, pu8dst1, u32H, u32W);
  std::future<int> Fun2 = std::async(function1, pu8src2, pu8dst2, u32H, u32W);
  std::future<int> Fun3 = std::async(function2, pu8src3, pu8dst3, u32H, u32W);  // 增加线程,占用的核心数增加

  // printf("please wait");
  // std::chrono::milliseconds span(1000);
  // while (Fun0.wait_for(span) != std::future_status::ready)
  //   printf("--->");
  // printf("\n");

  int ret = Fun0.get();
  ret = Fun1.get();
  ret = Fun2.get();
  ret = Fun3.get();

  
  uint32_t T3 = get_current_time();
  printf(" fun(%d) time:%dms \n",ret, T3-T1);

  free(pu8src);
  free(pu8dst);
  free(pu8src1);
  free(pu8dst1);
  free(pu8src2);
  free(pu8dst2);
  free(pu8src3);
  free(pu8dst3);

  return 0;
}

参考:https://blog.csdn.net/u012372584/article/details/97108417

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值