异步线程

时间:2015-11-06 14:21:23

标签: c asynchronous

我在C中有两个函数,它们将由c ++线程调用(每个函数一个线程)。我希望阻止一个,当另一个正在运行时,反之亦然。我该如何解决这个问题?

这里是简历:

int adin_mem_read(SP16 *buf, int sampnum, int client_id){

//(.....)
//lock writing_buffer
memcpy(&buf[real_size], stream_buffer_[client_id].data_ + stream_buffer_[client_id].p_read, stream_buffer_[client_id].p_write - stream_buffer_[client_id].p_read);
//unlock writing_buffer
//(....)
}

int writing_bufer(struct Stream_Bufer * buffers, const char *data, int nbytes, int end_stream, int begin_stream) {

//(...)
//lock adin_mem_read()
memcpy(buffers->data_ + buffers->p_write, data, nbytes);
buffers->p_write += nbytes;
//(...)
//unlock adin_mem_read()

}

0 个答案:

没有答案