我需要动态更新线程函数的参数。函数接收3个参数,并且:
void * operation_executer(void *args){
pthread_mutex_lock(&marketMutex);
struct exec_info *execData = args; //Parsing data from parameters
stock_market *market = execData->market; // Create stock market structure
pthread_mutex_unlock(&marketMutex);
pthread_mutex_lock(execData->exit_mutex);
// Waits until exit flag it's 1
while(*(execData->exit) == 0){
pthread_cond_wait(&exitCond, execData->exit_mutex);
}
pthread_mutex_unlock(execData->exit_mutex);
pthread_mutex_lock(&marketMutex);
struct operation op;
while(operations_queue_empty(market->stock_operations) == 0){
dequeue_operation(market->stock_operations, &op);
process_operation(market, &op);
}
pthread_mutex_unlock(&marketMutex);
}
#include "include/concurrency_layer.h";
int main(){
exit = 0;
exec_info info_ex1;
info_ex1.market = &market_madrid;
info_ex1.exit = &exit;
info_ex1.exit_mutex = &exit_mutex;
pthread_create(&(tid[1]), NULL, &operation_executer, (void*) &info_ex1);
pthread_mutex_lock(&exit_mutex);
exit = 1;
pthread_mutex_unlock(&exit_mutex);
pthread_join(tid[1],&res);
}
其思想是函数必须在
exit=1