📄 buffer.c
字号:
//// This example demonstrates semaphores.//#include <thread.h>#include <thread_semaphore.h>#include <string>class typeit : public pthread {protected: semaphore t_sem; string s; int i;public: typeit() { t_sem.wait(); i=0; t_sem.post(); }; ~typeit() { }; char text() { if ( t_sem.trywait() >= 0 ) return s[i++]; return 0; } int thread(void *) { int n=0; char buf[80]; cout << "launched" << endl; cin.getline(buf,80); n = strlen(buf); while( n-- > 0 ) t_sem.post(); s = buf; return 0; }};int main(){ char ch=0; typeit data; while( (ch=data.text()) != 0 ) cout << ch; cout << "." << endl; exit(0);}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -