diff options
author | nobody <nobody@ae88bc3d-4319-0410-8dbf-d08b4c9d3795> | 1999-07-26 18:15:56 +0000 |
---|---|---|
committer | nobody <nobody@ae88bc3d-4319-0410-8dbf-d08b4c9d3795> | 1999-07-26 18:15:56 +0000 |
commit | 3ec0a2984e41a8edf9301e8623d98aafdf9bf634 (patch) | |
tree | bf618e342e50289770a22c0f97cddef7caed6c4b /docs/tutorials/Chap_4/ex06.html | |
parent | 7aca63cabc7d12d4f0687c39fbe096b38fed9068 (diff) | |
download | ATCD-TAO-0_4_3.tar.gz |
This commit was manufactured by cvs2svn to create tag 'TAO-0_4_3'.TAO-0_4_3
Diffstat (limited to 'docs/tutorials/Chap_4/ex06.html')
-rw-r--r-- | docs/tutorials/Chap_4/ex06.html | 95 |
1 files changed, 0 insertions, 95 deletions
diff --git a/docs/tutorials/Chap_4/ex06.html b/docs/tutorials/Chap_4/ex06.html deleted file mode 100644 index 7a8df16dcd3..00000000000 --- a/docs/tutorials/Chap_4/ex06.html +++ /dev/null @@ -1,95 +0,0 @@ -<HTML> -<HEAD> - <META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1"> - <META NAME="Author" CONTENT="Ambreen Ilyas"> - <META NAME="GENERATOR" CONTENT="Mozilla/4.05 [en] (X11; I; SunOS 5.5.1 sun4u) [Netscape]"> - <TITLE>Example 6</TITLE> -</HEAD> -<BODY> -<FONT COLOR="#CC0000">/////////////////////////////////////////////////////////////////////////////////////////////////////////////////</FONT> -<BR><FONT COLOR="#CC0000">//// This example is from the ACE Programmers -Guide.</FONT> -<BR><FONT COLOR="#CC0000">//// Chapter: "Thread Management"</FONT> -<BR><FONT COLOR="#CC0000">//// For details please see the guide at</FONT> -<BR><FONT COLOR="#CC0000">//// http://www.cs.wustl.edu/~schmidt/ACE.html</FONT> -<BR><FONT COLOR="#CC0000">//// AUTHOR: Umar Syyid (usyyid@hns.com)</FONT> -<BR><FONT COLOR="#CC0000">//// and Ambreen Ilyas (ambreen@bitsmart.com)</FONT> -<BR><FONT COLOR="#CC0000">/////////////////////////////////////////////////////////////////////////////////////////////////////////////</FONT> - -<P><FONT COLOR="#CC0000">//Example 6</FONT> -<BR><FONT COLOR="#000099">#include</FONT> <FONT COLOR="#006600">"ace/Thread.h"</FONT> -<BR><FONT COLOR="#000099">#include</FONT> <FONT COLOR="#006600">"ace/OS.h"</FONT> -<BR><FONT COLOR="#000099">#include </FONT><FONT COLOR="#006600">"ace/Synch_T.h"</FONT> -<BR><FONT COLOR="#000099">#include</FONT><FONT COLOR="#006600"> "ace/Synch.h"</FONT> - -<P>static int number=0; -<BR>static int seed=0; - -<P>class Args{ -<BR>public: -<BR>Args(ACE_Condition<ACE_Thread_Mutex> *cond, int threads): -<BR> cond_(cond), threads_(threads){} -<BR>ACE_Condition<ACE_Thread_Mutex> *cond_; -<BR>int threads_; -<BR>}; - -<P>static void* -<BR>worker(void *arguments){ -<BR> Args *arg= (Args*)arguments; -<BR> ACE_DEBUG((LM_DEBUG,"Thread (%t) Created to do some work\n")); -<BR> ::number++; -<BR><FONT COLOR="#FF0000"> //Work</FONT> -<BR> ACE_OS::sleep(ACE_OS::rand()%2); - -<P><FONT COLOR="#FF0000"> //Exiting now</FONT> -<BR> ACE_DEBUG((LM_DEBUG, -<BR> "\tThread (%t) Done! \n\tThe number is now: %d\n",number)); -<BR><FONT COLOR="#FF0000"> //If all threads are done signal main thread -that program can now exit</FONT> -<BR> if(number==arg->threads_){ -<BR> ACE_DEBUG((LM_DEBUG, -<BR> "(%t) Last Thread!\n All threads have done -their job! -<BR> Signal main thread\n")); -<BR> arg->cond_->signal(); -<BR> } -<BR>return 0; -<BR>} -<BR> - -<P>int main(int argc, char *argv[]){ -<BR>if(argc<2){ -<BR> ACE_DEBUG((LM_DEBUG,"Usage: <program_name> <number of threads>\n")); -<BR> ACE_OS::exit(1); -<BR> } -<BR> -<BR>int n_threads=ACE_OS::atoi(argv[1]); - -<P><FONT COLOR="#FF0000">//Setup the random number generator</FONT> -<BR>ACE_OS::srand(::seed); - -<P><FONT COLOR="#FF0000">//Setup arguments for threads</FONT> -<BR>ACE_Thread_Mutex mutex; -<BR>ACE_Condition<ACE_Thread_Mutex> cond(mutex); -<BR>Args arg(&cond,n_threads); - -<P><FONT COLOR="#FF0000">//Spawn off n_threads number of threads</FONT> -<BR>for(int i=0; i<n_threads; i++){ -<BR> if(ACE_Thread::spawn((ACE_THR_FUNC)worker,(void*)&arg, -<BR> THR_DETACHED|THR_NEW_LWP)==-1) -<BR> ACE_DEBUG((LM_DEBUG,"Error in spawning thread\n")); -<BR> } - -<P><FONT COLOR="#FF0000">//Wait for signal indicating that all threads -are done and program can exit</FONT> -<BR>mutex.acquire(); -<BR>if(number!=n_threads) -<BR> cond.wait(); -<BR>ACE_DEBUG((LM_DEBUG,"(%t) Main Thread got signal. Program exiting..\n")); -<BR>mutex.release(); -<BR>ACE_OS::exit(0); -<BR>} - -<P> <A HREF="ex07.html">Next Example</A> -</BODY> -</HTML> |