std::recursive_timed_mutex::try_lock
Aus cppreference.com
|
|
This page has been machine-translated from the English version of the wiki using Google Translate.
The translation may contain errors and awkward wording. Hover over text to see the original version. You can help to fix errors and improve the translation. For instructions click here. |
<metanoindex/>
<tbody> </tbody> bool try_lock(); |
(seit C++11) | |
Versucht, den Mutex zu sperren. Kehrt sofort zurück. Bei erfolgreicher Sperre Akquisition Renditen
true, ansonsten false .Original:
Tries to lock the mutex. Returns immediately. On successful lock acquisition returns
true, otherwise returns false.The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
You can help to correct and verify the translation. Click here for instructions.
Parameter
(None)
Original:
(none)
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
You can help to correct and verify the translation. Click here for instructions.
Rückgabewert
true wenn die Sperre wurde erfolgreich erfasst, sonst false .Original:
true if the lock was acquired successfully, otherwise false.The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
You can help to correct and verify the translation. Click here for instructions.
Ausnahmen
| This section is incomplete |
Beispiel
Dieses Beispiel zeigt, Schloss, try_lock und entsperren in Aktion
Original:
This example shows lock, try_lock and unlock in action
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
You can help to correct and verify the translation. Click here for instructions.
#include <iostream>
#include <mutex>
int main()
{
std::mutex test;
if (test.try_lock()==true)
std::cout << "lock acquired" << std::endl;
else
std::cout << "lock not acquired" << std::endl;
test.unlock(); //now unlock the mutex
test.lock(); //to lock it again
if (test.try_lock()) //true can be left out
std::cout << "lock acquired" << std::endl;
else
std::cout << "lock not acquired" << std::endl;
test.lock(); //and now the finale (a block)
}
Output:
lock acquired
lock not acquired
(program hangs)
Siehe auch
| sperrt den Mutex, blockiert wenn der Mutex nicht verfügbar ist (öffentliche Elementfunktion) | |
versucht, den Mutex zu sperren, kehrt zurück, wenn der Mutex hat been unavailable für das angegebene Timeout-Dauer Original: tries to lock the mutex, returns if the mutex has been unavailable for the specified timeout duration The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (öffentliche Elementfunktion) | |
versucht, den Mutex verriegeln, zurückgibt, wenn der Mutex hat been unavailable bis bestimmten Zeitpunkt erreicht worden ist Original: tries to lock the mutex, returns if the mutex has been unavailable until specified time point has been reached The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (öffentliche Elementfunktion) | |
| entsperrt den Mutex (öffentliche Elementfunktion) | |