Code/Resource
Windows Develop
Linux-Unix program
Internet-Socket-Network
Web Server
Browser Client
Ftp Server
Ftp Client
Browser Plugins
Proxy Server
Email Server
Email Client
WEB Mail
Firewall-Security
Telnet Server
Telnet Client
ICQ-IM-Chat
Search Engine
Sniffer Package capture
Remote Control
xml-soap-webservice
P2P
WEB(ASP,PHP,...)
TCP/IP Stack
SNMP
Grid Computing
SilverLight
DNS
Cluster Service
Network Security
Communication-Mobile
Game Program
Editor
Multimedia program
Graph program
Compiler program
Compress-Decompress algrithms
Crypt_Decrypt algrithms
Mathimatics-Numerical algorithms
MultiLanguage
Disk/Storage
Java Develop
assembly language
Applications
Other systems
Database system
Embeded-SCM Develop
FlashMX/Flex
source in ebook
Delphi VCL
OS Develop
MiddleWare
MPI
MacOS develop
LabView
ELanguage
Software/Tools
E-Books
Artical/Document
buffer.C
Package: threads-2.0.tar.gz [view]
Upload User: shtangtang
Upload Date: 2007-01-04
Package Size: 167k
Code Size: 1k
Category:
Linux-Unix program
Development Platform:
Unix_Linux
- //
- // 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);
- }