There is a task:

The parent thread of the program must read user-entered strings and put them at the beginning of the linked list. Lines longer than 80 characters can be cut into several lines. When you enter a blank line, the program should display the current state of the list. The child thread wakes up every five seconds and sorts the list in lexicographical order (use bubble sort). All list operations should be synchronized using mutex.

How can I solve this problem? Tell me where to start.

Closed due to the fact that the essence of the question is not clear to the participants of PashaPash , Nick Volynkin , Suvitruf , Mike , tutankhamun 14 December '15 at 6:43

Try to write more detailed questions. To get an answer, explain what exactly you see the problem, how to reproduce it, what you want to get as a result, etc. Give an example that clearly demonstrates the problem. If the question can be reformulated according to the rules set out in the certificate , edit it .

  • five
    Start with the Main function. - VladD
  • Start with the basics of working with threads - launching them, pausing for a while (Sleep), synchronization objects (mutex). - PashaPash

1 answer 1

For example, you can somehow like this:

 IEnumerable<string> InputLines() { while (true) yield return Console.ReadLine(); } List<string> lines = new List<string>(); foreach (var l in InputLines()) lock (mutex) if (l == "") Output(lines); else lines.Add(l); // в новом потоке while (true) { await Task.Delay(5000); lock (mutex) lines.Sort(); } 

Understand.

  • say mutex - fake! :) - PashaPash
  • @PashaPash: Let's use duck typing: if you can lock it, then it's a mutex :) - VladD