Began work on rewrite, need to fix .gitignore

This commit is contained in:
Trimutex 2023-09-30 01:13:54 -05:00
parent cc190c213b
commit 7dd80a5782
2 changed files with 40 additions and 21 deletions

View File

@ -1,5 +1,9 @@
add_executable(proxy-network add_executable(proxy-network
./proxy-network.cpp ./mt_web_server.cpp
)
add_executable(tempmulti
./multi_threads.cpp
) )
target_include_directories(proxy-network PUBLIC ${CMAKE_CURRENT_LIST_DIR}) target_include_directories(proxy-network PUBLIC ${CMAKE_CURRENT_LIST_DIR})

View File

@ -17,36 +17,51 @@
* September 12, 11:00 AM at Edwardsville, IL * * September 12, 11:00 AM at Edwardsville, IL *
* * * *
* ************************************************************************* */ * ************************************************************************* */
#include <ratio>
#define UNIX // WIN for Windows environment, UNIX for BSD or LINUX env.
/* FOR WIN ------------------------------------------------------------- */
#ifdef WIN
#include <process.h> // for thread system calls (_beginthread, etc.) #include <process.h> // for thread system calls (_beginthread, etc.)
#include <windows.h> // for TRUE, FALSE labels #include <windows.h> // for TRUE, FALSE labels
#endif
/* --------------------------------------------------------------------- */
/* FOR UNIX/LINUX ------------------------------------------------------ */
#ifdef UNIX
#endif
/* --------------------------------------------------------------------- */
#include <chrono>
#include <thread>
#include <stdio.h> // for printf #include <stdio.h> // for printf
#include <time.h> // for clock() and CLK_TCK #include <time.h> // for clock() and CLK_TCK
/* Global label defenition ------------------------------------------------ */ /* Global label defenition ------------------------------------------------ */
#define INTERVAL 1 // Transmission interval in seconds #define INTERVAL 1 // Transmission interval in seconds
#define REPEATS 50 // Number of child thread's repeats #define REPEATS 10 // Number of child thread's repeats
/* Global Variables ------------------------------------------------------- */ /* Global Variables ------------------------------------------------------- */
int nChild1_status; // Child thread #1 status int nChild1_status; // Child thread #1 status
int nChild2_status; // Child thread #2 status int nChild2_status; // Child thread #2 status
/* Prototypes ------------------------------------------------------------- */ /* Prototypes ------------------------------------------------------------- */
void ChildThread1(void *dummy); // The child thread #1 void ChildThread1(void); // The child thread #1
void ChildThread2(void *dummy); // The child thread #2 void ChildThread2(void); // The child thread #2
/* The MAIN --------------------------------------------------------------- */ /* The MAIN --------------------------------------------------------------- */
void main (void) int main (void)
{ {
/* Set the child thread status (TRUE = RUNNING) --- */ /* Set the child thread status (TRUE = RUNNING) --- */
nChild1_status = TRUE; nChild1_status = true;
nChild2_status = TRUE; nChild2_status = true;
/* Create and start the two threads --- */ /* Create and start the two threads --- */
_beginthread (ChildThread1, 0, NULL ); // Start child process #1 std::thread nChild1(ChildThread1); // Start child process #1
_beginthread (ChildThread2, 0, NULL ); // Start child process #2 std::thread nChild2(ChildThread2); // Start child process #2
nChild1.join();
nChild2.join();
/* Spin-loop until both threads finish --- */ /* Spin-loop until both threads finish --- */
while ((nChild1_status == TRUE)||(nChild2_status == TRUE)) while ((nChild1_status == true)||(nChild2_status == true))
{ ; } { ; }
/* Two threads are now finished --- */ /* Two threads are now finished --- */
@ -55,7 +70,7 @@ void main (void)
} }
// The Child-Thread #1 /////////////////////////////////////////////////////// // The Child-Thread #1 ///////////////////////////////////////////////////////
void ChildThread1(void *dummy) void ChildThread1(void)
{ {
/* Child #1 local variable(s) --- */ /* Child #1 local variable(s) --- */
int i; // Loop counter int i; // Loop counter
@ -67,21 +82,21 @@ void ChildThread1(void *dummy)
for (i = 0; i < REPEATS; i++) for (i = 0; i < REPEATS; i++)
{ {
/* Wait for 10 seconds --- */ /* Wait for 10 seconds --- */
Sleep((clock_t)INTERVAL * CLOCKS_PER_SEC); std::this_thread::sleep_for(std::chrono::duration<double, std::milli>(1000));
/* Display count down --- */ /* Display count down --- */
printf("Child #1: %d more second(s) to finish ...\n", REPEATS -i); printf("Child #1: %d more second(s) to finish ...\n", REPEATS -i);
} }
/* Reset the status flag --- */ /* Reset the status flag --- */
nChild1_status = FALSE; nChild1_status = false;
/* Terminate this thread --- */ /* Terminate this thread --- */
_endthread(); //_endthread();
} }
// The Child-Thread #2 /////////////////////////////////////////////////////// // The Child-Thread #2 ///////////////////////////////////////////////////////
void ChildThread2(void *dummy) void ChildThread2(void)
{ {
/* Child #2 local variable(s) --- */ /* Child #2 local variable(s) --- */
int i; // Loop counter int i; // Loop counter
@ -93,17 +108,17 @@ void ChildThread2(void *dummy)
for (i = 0; i < REPEATS; i++) for (i = 0; i < REPEATS; i++)
{ {
/* Wait for 10 seconds --- */ /* Wait for 10 seconds --- */
Sleep((clock_t)INTERVAL * CLOCKS_PER_SEC); std::this_thread::sleep_for(std::chrono::duration<double, std::milli>(1000));
/* Display count down --- */ /* Display count down --- */
printf("Child #2: %d more second(s) to finish ...\n", REPEATS -i); printf("Child #2: %d more second(s) to finish ...\n", REPEATS -i);
} }
/* Reset the status flag --- */ /* Reset the status flag --- */
nChild2_status = FALSE; nChild2_status = false;
/* Terminate this thread --- */ /* Terminate this thread --- */
_endthread(); //_endthread();
} }
// THE END OF LINES ////////////////////////////////////////////////////////// // THE END OF LINES //////////////////////////////////////////////////////////