对于我的游戏项目点,我使用多线程来显示为用户传递的时间但是在用户输入时光标在完成输入之前重叠用户输入所以我想将一个线程修复到控制台而不影响用户输入
你需要的是这样的东西,这是我从Linux系统编程书中获得的笔记:
Manual File Locking
函数flockfile()等待直到流不再被锁定,碰撞锁定计数,然后获取锁,成为流的拥有线程,并返回:
#include <stdio.h>
void flockfile (FILE *stream);
funlockfile()函数减少与stream关联的锁定计数:
#include <stdio.h>
void funlockfile (FILE *stream)
flockfile (stream);
fputs ("List of treasure:\n", stream);
fputs (" (1) 500 gold coins\n", stream);
fputs (" (2) Wonderfully ornate dishware\n", stream);
funlockfile (stream);
希望有所帮助。