5线程都想打开文件需要async / await实现同样请帮忙。 [英] 5 Threads all want to open an document need async/await implementation for the same please help.
本文介绍了5线程都想打开文件需要async / await实现同样请帮忙。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
5个线程都想打开文件需要async / await实现
Thread1 ---->尝试打开doc1
Thread2 ---->尝试打开doc1
Thread3 ---->尝试打开doc1
Thread4 ---->尝试打开doc1
Threadn ---->尝试打开doc1
5 Threads all want to open an document need async/await implementation
Thread1----> trying Opening a doc1
Thread2----> trying Opening a doc1
Thread3----> trying Opening a doc1
Thread4----> trying Opening a doc1
Threadn----> trying Opening a doc1
推荐答案
当两个或多个线程需要访问共享资源时同时,系统需要一个同步机制来确保一次只有一个线程使用该资源。 Mutex是一个同步原语,它只允许对一个线程的共享资源进行独占访问。如果一个线程获得一个互斥锁,那么想要获取该互斥锁的第二个线程将被挂起,直到第一个线程释放该互斥锁。
请点击以下链接获取更多信息。
https://msdn.microsoft.com/en-us/library/system.threading.mutex%28v=vs.110%29.aspx [ ^ ]
谢谢。!!!
Hi,
When two or more threads need to access a shared resource at the same time, the system needs a synchronization mechanism to ensure that only one thread at a time uses the resource. Mutex is a synchronization primitive that grants exclusive access to the shared resource to only one thread. If a thread acquires a mutex, the second thread that wants to acquire that mutex is suspended until the first thread releases the mutex.
Please follow below link for more information.
https://msdn.microsoft.com/en-us/library/system.threading.mutex%28v=vs.110%29.aspx[^]
Thanks.!!!
这篇关于5线程都想打开文件需要async / await实现同样请帮忙。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文