Espacios de nombres
Variantes
Acciones

std::mutex::try_lock

De cppreference.com
< cpp‎ | thread‎ | mutex

 
 
Tema Biblioteca de ayuda
Threads
Original:
Threads
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
(C++11)
this_thread espacio de nombres
Original:
this_thread namespace
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
(C++11)
(C++11)
(C++11)
Exclusión mutua
Original:
Mutual exclusion
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
(C++11)
Gestión de bloqueos genérico
Original:
Generic lock management
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
(C++11)
(C++11)
(C++11)
(C++11)(C++11)(C++11)
Las variables de condición
Original:
Condition variables
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
(C++11)
Futuros
Original:
Futures
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
(C++11)
(C++11)
(C++11)
(C++11)
 
std::mutex
Las funciones miembro
Original:
Member functions
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Bloqueo
Original:
Locking
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
mutex::try_lock
Identificador nativo
Original:
Native handle
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
 
bool try_lock();
(desde C++11)
Intenta bloquear el mutex. Vuelve inmediatamente. El éxito vuelve bloqueo adquisición true lo contrario, devuelve 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.

Contenido

[editar] Parámetros

(Ninguno)
Original:
(none)
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

[editar] Valor de retorno

true si el bloqueo se adquirió con éxito, de lo contrario 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.

[editar] Excepciones

[editar] Ejemplo

Este ejemplo muestra la cerradura, try_lock y desbloquear en acción
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.

#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)
}

Salida:

lock acquired
lock not acquired
(program hangs)

[editar] Ver también

bloquea el mutex, si bloquea el mutex no está disponible
Original:
locks the mutex, blocks if the mutex is not available
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

(función miembro público) [editar]
desbloquea el mutex
Original:
unlocks the mutex
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

(función miembro público) [editar]