iOS開発者の役割に関するインタビューでこの質問をしました。プロトコルを使用して同時実行スレッドを実装するにはどうすればよいですか?
// Please design a read-write task queue where you can tag the reader task with label,
// where the the task with the same label should be executed sequentially, and the
// tasks with different labels could be executed concurrently. However, the writer
// would get the exclusive access where no concurrent task would happen at the
// same time with the writer task
// For example:
protocol ConcurrentQueueWithSerialization {
// Submits a labeled task.
// All tasks with the same label will be serialized.
// Tasks with different labels will run concurrently.
// Use this method to submit a "read" operation from a particular reader.
func async(with label: String, task: @escaping() -> Void)
// Submits a task that will run concurrently with all other tasks regardless of their labels.
func async(task: @escaping() -> Void)
// Submits a labeled and delayed task.
func asyncAfter(deadline: DispatchTime, with label: String, task: @escaping() -> Void)
// Submits an unlabeled and delayed task.
func asyncAfter(deadline: DispatchTime, task: @escaping() -> Void)
// Submits a barrier task. Only one barrier task is allowed to run at a time.
// Works as a critical section for the queue.
// Use this method to submit a writer task.
func asyncBarrier(task: @escaping() -> Void)
}
class MyDispatchQueue: ConcurrentQueueWithSerialization {
//TODO: write your implementation
}
Interviewerは、上記のプロトコルをMyDispatchQueueクラスに実装するように求めました。私は試しましたが、解決策が見つかりませんでした。私を助けてください。前もって感謝します。
SOはコード作成サービスではありません。何を試しましたか?あなたはどんな問題にぶつかったのですか? – Alexander
あなたの質問には要件だけが含まれています。あなた自身がこの問題を解決するための努力を示しているわけではありません。このサイトは無料の「私たちはあなたの(自宅)仕事をしている」サービスではないので、この質問にあなたの試みを加えてください。それを超えて:[ヘルプ]を見て、ここでどのように/何を尋ねるかを学んでください。ありがとう! – GhostCat