|
|
没怎么写过多线程,用mutex锁了一下,但没锁住~~~
请教各位该如何做。
我的代码 大概像下面这个样子..l
thread1()
{
pthread_mutex_lock(stdin_mutex);
while((c=getchar())!=EOF)
{
getchar();
pthread_mutex_unlock(stdin_mutex);
switch(c)
{
......
.......
}
pthread_mutex_lock(stdin_mutex);
}//while end
}
thread2()
{
while (event_loop)
{
.....
{
//有时候需要读取键盘输入
pthread_mutex_lock(stdin_mutex);
fgets(.....);
pthread_mutex_unlock(stdin_mutex);
}
......
}
} |
|