将互斥锁数组传递给函数时出错C2664

时间:2015-05-13 02:14:41

标签: c++ multithreading mutex

我试图将一组互斥锁传递给一个线程调用的函数。我收到了这个错误:

cannot convert argument 2 from 'std::mutex *' to 'std::mutex (&)[5]

声明

void Philosopher::Live(std::mutex (&fork_)[5])

呼叫

thread_[i] = std::thread(&Philosopher::Live, philosopher_[i], fork_);

1 个答案:

答案 0 :(得分:1)

大多数表达式中使用的T数组将降级为指向T的指针,其值等于第一个数组元素的地址。模板的参数转发机制不知道您要将参数作为对数组的引用转发,因此数组参数作为其降级值传递。

要将数组作为参考传递,您可以使用std::ref

thread_[i] = std::thread(&Philosopher::Live, philosopher_[i], std::ref(fork_));

或者,您可以选择std::vector使用std::arrayfork_ Live,并修改 <?php # Convert result to csv and push use to download if user pressed "Download" button if(isset($_POST["downloadquery"])) { $fp = fopen('php://output', 'w'); ob_start(); if ($fp && $result) { fputcsv($fp, $headers); # populate header while ($row = $result->fetch_array(MYSQLI_NUM)) { fputcsv($fp, array_values($row)); #populate rows } } $content = ob_get_clean(); $filename ='queryResults' . date('Ymd'); // Output CSV-specific headers header('Pragma: public'); header('Expires: 0'); header('Cache-Control: must-revalidate, post-check=0, pre-check=0'); header('Cache-Control: private', false); header('Content-Type: application/octet-stream'); header('Content-Disposition: attachment; filename="' . $filename . '.txt";'); exit($content); } ?> 方法以获取对此的引用。