简体   繁体   English

在C编程中使用pther线程printf时从线程进行多线程scanf

[英]multi threading scanf from thread while pther thread printf in c programming

对于我的游戏项目点,我使用多线程来显示用户经过的时间,但是在用户输入时,光标在完成输入之前会与用户输入重叠,因此我想在不影响用户输入的情况下将线程固定到控制台

What you need is something like this, which is in my notes taken from Linux System Programming book: 您需要的是这样的东西,这在我从Linux系统编程一书中摘录的内容中:

Manual File Locking

The function flockfile() waits until stream is no longer locked, bumps the lock count, and then acquires the lock, becoming the owning thread of the stream, and returns: 函数flockfile()等待直到流不再被锁定,增加锁计数,然后获取该锁,成为流的拥有线程,并返回:

#include <stdio.h> void flockfile (FILE *stream);

The function funlockfile() decrements the lock count associated with stream: 函数funlockfile()减少与流关联的锁计数:

#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);

Hope that helps. 希望能有所帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM