You can't actually cross the border on the train, so it will involve you doing border control after exiting the train on the Thailand side of the border, and getting on a different train in Malaysia.
*********************************************************************