diff options
Diffstat (limited to 'docs/tutorials/Chap_4/ex07.html')
-rw-r--r-- | docs/tutorials/Chap_4/ex07.html | 84 |
1 files changed, 0 insertions, 84 deletions
diff --git a/docs/tutorials/Chap_4/ex07.html b/docs/tutorials/Chap_4/ex07.html deleted file mode 100644 index 4adf56569d3..00000000000 --- a/docs/tutorials/Chap_4/ex07.html +++ /dev/null @@ -1,84 +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 7</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 7</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_Barrier *barrier): -<BR> barrier_(barrier){} -<BR>ACE_Barrier *barrier_; -<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> -<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"> //Let the barrier know we are done.</FONT> -<BR> arg->barrier_->wait(); -<BR> ACE_DEBUG((LM_DEBUG,"Thread (%t) is exiting \n")); -<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]); -<BR>ACE_DEBUG((LM_DEBUG,"Preparing to spawn %d threads",n_threads)); -<BR><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_Barrier barrier(n_threads); -<BR>Args arg(&barrier); - -<P><FONT COLOR="#FF0000">//Spawn off n_threads number of threads</FONT> -<BR>for(int i=0; i<n_threads; i++){ if(ACE_Thread::spawn((ACE_THR_FUNC)worker,(void*)&arg,THR_DETACHED|THR_NEW_LWP)==-1) -<BR> ACE_DEBUG((LM_DEBUG,"Error in spawning thread\n")); -<BR> } - -<P><FONT COLOR="#FF0000">//Wait for all the other threads to let the main -thread</FONT> -<BR><FONT COLOR="#FF0000">// know that they are done using hte barrier</FONT> -<BR>barrier.wait(); -<BR>ACE_DEBUG((LM_DEBUG,"(%t)Other threads are finished. Program exiting..\n")); -<BR>ACE_OS::sleep(2); -<BR>} - -<P> <A HREF="ex08.html">Next Example</A> -</BODY> -</HTML> |