You can make things so the figure environment shares the counter with lstlisting. However, you should ensure that lstlisting environments are floating too, otherwise the numbers could not agree and a figure could appear before a listing with a lower number.
\documentclass{article}
\usepackage{listings}
\makeatletter
\AtBeginDocument{%
\let\c@figure\c@lstlisting
\let\thefigure\thelstlisting
\let\ftype@lstlisting\ftype@figure % give the floats the same precedence
}
\makeatother
\begin{document}
\begin{lstlisting}[caption=A listing,float]
a=1
\end{lstlisting}
\begin{lstlisting}[caption=Another,float]
b=2
\end{lstlisting}
\begin{figure}
F
\caption{A figure}
\end{figure}
\begin{lstlisting}[caption=Again,float]
c=3
\end{lstlisting}
\end{document}

Thanks to David Carlisle for noting the need for adjusting \ftype@lstlisting.
If you also want that table shares the counter, add similar instructions.
\documentclass{article}
\usepackage{listings}
\makeatletter
\AtBeginDocument{%
\let\c@figure\c@lstlisting
\let\thefigure\thelstlisting
\let\c@table\c@lstlisting
\let\thetable\thelstlisting
\let\ftype@lstlisting\ftype@figure % give the floats the same precedence
\let\ftype@table\ftype@figure % give the floats the same precedence
}
\makeatother
\begin{document}
\begin{lstlisting}[caption=A listing,float]
a=1
\end{lstlisting}
\begin{lstlisting}[caption=Another,float]
b=2
\end{lstlisting}
\begin{figure}
F
\caption{A figure}
\end{figure}
\begin{table}
G
\caption{A table}
\end{table}
\begin{lstlisting}[caption=Again,float]
c=3
\end{lstlisting}
\end{document}
\let\c@lstlisting\c@figure...\let\thelstlisting\thefigure...\let\ftype@figure\ftype@lstlisting..." – badroit May 08 '14 at 20:53tablecounter was shared right from the start. – Jun 06 '17 at 17:57xassoccntpackage – Jun 06 '17 at 18:16\let\c@lstlisting\c@figure...\let\thelstlisting\thefigure...\let\ftype@figure\ftype@lstlisting) solution causesYou can't use `\relax' after \thewith the latest latex and how this can be corrected in a backward compatible way? – Leonid Oct 11 '20 at 20:15LaTeX2e <2020-10-01> patch level 1. The two given codes run flawlessly. – egreg Oct 11 '20 at 21:18\usepackage{caption}; read the manual. – egreg Jan 03 '23 at 18:30