  We investigate the $B^0\to \pi^- K^+ X(3872)$ decay via the
$D_{s1}(2536)\bar{D} D^*$ rescattering diagram. The line shape of the
$K^+X(3872)$ distribution curve around $D_{s1}(2536)\bar{D}$ threshold is very
sensitive to the $X(3872)$ mass because the triangle singularity (TS) can be
generated from the loop. By means of this characteristic, we can determine
whether the $X(3872)$ mass is below or above the $D^{\ast 0}\bar{D}^0$
threshold with high precision. The narrowness of $D_{s1}(2536)$ in the loop is
one of the key reasons why the TS mechanism of measuring the $X(3872)$ mass may
work. The $X(3872)$ width impact on the $K^+X(3872)$ line shape is also crucial
in the TS mechanism. If the width is as large as 1 MeV, the proposed method of
measuring the $X(3872)$ mass would be ruined.
