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
consumer.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
- #define __THREADS_MAIN
- #include <thread.h>
- #include <string>
- extern "C" {
- # include <unistd.h>
- };
- cond t_control;
- mutex t_link;
- string s;
- class producer : public pthread {
- public:
- producer() { };
- ~producer() { };
- int thread(void *)
- {
- char *buf = new char[80];
- cout << "Enter text for consumer: ";
- cout.flush();
- cin.getline(buf,80);
- t_link.lock();
- s = buf;
- t_control.signal();
- t_link.unlock();
- delete buf;
- return 0;
- }
- };
- class consumer : public pthread {
- public:
- consumer() { };
- ~consumer() { };
- int thread(void *)
- {
- int r;
- t_link.lock();
- t_control.wait(t_link);
- cout << "Consumed: '" << s << "'n";
- r = s.length();
- t_link.unlock();
- return r;
- }
- };
- void
- hexdump(const unsigned char *ptr, int len)
- {
- string s;
- int i = 0;
- while(i < len) {
- if( (i%16) == 0 ) {
- if ( i > 0 )
- cout << " ;" << s.c_str() << endl;
- cout.form("%08X ",(int)ptr);
- s = "";
- }
- cout.form(" %02X",(unsigned int)ptr[i]);
- if ( isprint(ptr[i]) )
- s += ptr[i];
- else
- s += '.';
- i += 1;
- }
- while( (i%16) )
- cout << " ",i++;
- cout << " ;" << s.c_str() << endl;
- }
- int main()
- {
- pthread *p1, *p2;
- p1 = new consumer;
- p2 = new producer;
- p1->join();
- cout << "return value " << p1->retcode() << endl;
- }