3.1 Multi threaded Signal Finder - KeonYeong/LKY GitHub Wiki
Overview :
Using threads, main function will find the words that exist in the signals. Searching algorithm is applied using aho-corasick algorithm. Threads will wake up if there are 'Q' sign input to main function, after the searching finished , threads call 'wait' function with certain condition variable.
Main Function:
-
Main Function creates threads according to the constant int 'NUM_THREAD' and initialize any resources or variables that threads need. Main function also divide its word list into NUM_THREAD and give certain number of words to every threads.
-
Waiting for the commands input, and the behavior of main function is divided into 3 types according to 'Q', 'A', 'D'.
-
If Q is input, then main function wakes up every threads and wait threads finish their works.
-
If A is input, main function add new word into the upcoming thread's word list.
-
If D is input, main function searches the certain word from threads' word lists and delete that from the word list found.
-
- Every time the word list of thread is changed, thread re-create the Trie structure before beginning searching signal.
Thread Function:
- Basically, they are in infinite loop so that only they need to do are waiting and waking up before work.
- If they get signal so that they wake up, they first make Trie structure if there are any change in their word lists. After they also create failure link and then finally search for the words in signal they get.
- If they finished searching they put their results into multimap called 'resultMap' and call 'wait' function with condition variable.
- They all have own data structure called 'threadData' which includes word list for thread, and some more flags that express thread's state.
Others:
- NUM_THREAD is fit to 36, because of the numbers of core in server.
- Searching Algorithm is Aho-corasick algorithm.