I recently encountered a issue that the program does not get the expected result occasionally, and sometimes it hangs. The following is the code snippets. Thanks in advance