{"id":395888,"date":"2024-06-29T12:30:02","date_gmt":"2024-06-29T12:30:02","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=395888"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=395888","title":{"rendered":"<span>\u041e\u0431\u044a\u0435\u043a\u0442\u043d\u043e-\u043e\u0440\u0438\u0435\u043d\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u043e\u0435 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u043d\u0430 \u0421\u0438 \u0431\u0435\u0437 \u043f\u043b\u044e\u0441\u043e\u0432. \u0427\u0430\u0441\u0442\u044c 2. \u0422\u0430\u0439\u043c\u0435\u0440<\/span>"},"content":{"rendered":"<div><!--[--><!--]--><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<p>\u00a0\u00a0 \u00a0\u0412\u0440\u0435\u043c\u044f \u044d\u0442\u043e \u043e\u0434\u043d\u043e \u0438\u0437 \u0438\u0437\u043c\u0435\u0440\u0435\u043d\u0438\u0439 \u043e\u043a\u0440\u0443\u0436\u0430\u044e\u0449\u0435\u0433\u043e \u043d\u0430\u0441 \u043c\u0438\u0440\u0430, \u0430 \u043b\u044e\u0431\u0430\u044f \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u043c\u0430\u044f \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u044c \u0438\u043b\u0438 \u043d\u0430\u0445\u043e\u0434\u0438\u0442\u0441\u044f (\u0443\u0441\u043b\u043e\u0432\u043d\u043e) \u0432 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0438 \u043f\u043e\u043a\u043e\u044f, \u0438\u043b\u0438 \u0438\u0437\u043c\u0435\u043d\u044f\u0435\u0442 \u0441\u0432\u043e\u0451 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435 \u0432 \u0442\u0435\u0447\u0435\u043d\u0438\u0435 \u0432\u0440\u0435\u043c\u0435\u043d\u0438. \u0418, \u0435\u0441\u0442\u0435\u0441\u0442\u0432\u0435\u043d\u043d\u043e \u0435\u0441\u043b\u0438 \u043d\u0435\u0442 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u0438 \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u044f \u0432\u0440\u0435\u043c\u0435\u043d\u0438, \u0447\u0442\u043e-\u0442\u043e \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0435\u043d\u043d\u043e\u0435 \u0441\u0432\u0430\u0440\u0433\u0430\u043d\u0438\u0442\u044c \u043d\u0435 \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u0441\u044f. \u041f\u043e\u044d\u0442\u043e\u043c\u0443 \u043f\u0435\u0440\u0432\u043e\u0435, \u0447\u0442\u043e \u0434\u043e\u043b\u0436\u043d\u043e \u0431\u044b\u0442\u044c &#8212; \u044d\u0442\u043e \u0440\u0435\u0448\u0435\u043d\u0438\u0435 \u0432 \u0432\u0438\u0434\u0435 \u0442\u0430\u0439\u043c\u0435\u0440\u0430. <\/p>\n<p>    \u00a0\u00a0 \u00a0\u0414\u043b\u044f Linux \u0432 \u0421\u0438 \u0432 \u043d\u0430\u0441\u0442\u043e\u044f\u0449\u0435\u0435 \u0432\u0440\u0435\u043c\u044f \u0435\u0441\u0442\u044c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0438:<\/p>\n<p><strong>unsigned int sleep(unsigned int __seconds); <\/strong>,<\/p>\n<p>\u043e\u0431\u044a\u044f\u0432\u043b\u0435\u043d\u043d\u0430\u044f \u0432 \u0444\u0430\u0439\u043b\u0435 <strong>&lt;unistd.h><\/strong> \u0438 <\/p>\n<p><strong>    int nanosleep(const struct timespec *req, struct timespec *rem); ,<\/strong><\/p>\n<p>\u043e\u0431\u044a\u044f\u0432\u043b\u0435\u043d\u043d\u0430\u044f \u0432 \u0444\u0430\u0439\u043b\u0435 <strong>&lt;time.h><\/strong><\/p>\n<p>    \u00a0\u00a0 \u00a0\u041e\u0431\u0435 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u044e\u0442 \u043e\u0434\u043d\u0443 \u0437\u0430\u0434\u0430\u0447\u0443, \u043f\u0440\u0438\u043e\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u044e\u0442 \u0440\u0430\u0431\u043e\u0442\u0443 \u043f\u043e\u0442\u043e\u043a\u0430 \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u0431\u044b\u043b\u0430 \u0432\u044b\u0437\u0432\u0430\u043d\u0430 \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u043d\u0430 \u0437\u0430\u0434\u0430\u043d\u043d\u043e\u0435 \u0432\u0440\u0435\u043c\u044f, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u0441 \u0434\u0430\u043d\u043d\u044b\u043c\u0438 \u0444\u0443\u043d\u043a\u0446\u0438\u044f\u043c\u0438 \u043e\u0447\u0435\u0432\u0438\u0434\u043d\u044b\u043c \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043f\u0440\u043e\u0441\u0442\u043e\u0435 \u0440\u0435\u0448\u0435\u043d\u0438\u0435 (\u043a\u0430\u043a \u0433\u043e\u0432\u043e\u0440\u0438\u0442\u0441\u044f \u00ab\u0440\u0435\u0448\u0435\u043d\u0438\u0435 \u0432 \u043b\u043e\u0431\u00bb) \u0432\u044b\u0434\u0435\u043b\u0438\u0442\u044c \u0434\u043b\u044f \u0442\u0430\u0439\u043c\u0435\u0440\u0430 \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u044b\u0439 \u043f\u043e\u0442\u043e\u043a.<\/p>\n<p>    \u00a0\u00a0 \u00a0\u0415\u0441\u0442\u044c \u0435\u0449\u0451 \u0444\u0443\u043d\u043a\u0446\u0438\u044f <strong>clock_nanosleep()<\/strong>, \u043c\u043e\u0436\u043d\u043e \u0432\u043a\u043b\u044e\u0447\u0438\u0442\u044c \u0440\u0435\u0436\u0438\u043c\u044b <strong>SHED_FIFO<\/strong> \u0438\u043b\u0438 <strong>SCHED_RR<\/strong> \u0434\u043b\u044f \u0431\u043e\u043b\u0435\u0435 \u0442\u043e\u0447\u043d\u043e\u0439 \u0440\u0430\u0431\u043e\u0442\u044b, \u0432\u0441\u0451 \u044d\u0442\u043e \u043a\u043e\u043d\u0435\u0447\u043d\u043e \u0445\u043e\u0440\u043e\u0448\u043e, \u043d\u043e \u044f \u0440\u0435\u0448\u0438\u043b \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0438\u0442\u044c\u0441\u044f \u0442\u043e\u043b\u044c\u043a\u043e \u0432\u044b\u0448\u0435 \u0443\u043a\u0430\u0437\u0430\u043d\u043d\u044b\u043c\u0438.  <\/p>\n<p>    \u00a0\u00a0 \u00a0\u0422\u0430\u0439\u043c\u0435\u0440 \u0434\u043e\u043b\u0436\u0435\u043d \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u043e\u0432\u0430\u0442\u044c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c \u0442\u0440\u0435\u0431\u043e\u0432\u0430\u043d\u0438\u044f: \u0434\u043e\u043b\u0436\u0435\u043d \u043c\u0438\u043d\u0438\u043c\u0430\u043b\u044c\u043d\u043e \u043f\u043e\u0442\u0440\u0435\u0431\u043b\u044f\u0442\u044c \u0432\u044b\u0447\u0438\u0441\u043b\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0435 \u0440\u0435\u0441\u0443\u0440\u0441\u044b,  \u0434\u043e\u043b\u0436\u0435\u043d \u043c\u0433\u043d\u043e\u0432\u0435\u043d\u043d\u043e \u0432\u043a\u043b\u044e\u0447\u0430\u0442\u044c\u0441\u044f\/\u0432\u044b\u043a\u043b\u044e\u0447\u0430\u0442\u044c\u0441\u044f, \u043f\u0440\u0438 \u044d\u0442\u043e\u043c \u0441\u0431\u0440\u0430\u0441\u044b\u0432\u0430\u0442\u044c \u0441\u0432\u043e\u0451 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435 \u0438 \u043e\u0431\u044f\u0437\u0430\u0442\u0435\u043b\u044c\u043d\u043e \u0431\u044b\u0442\u044c \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u0442\u043e\u0447\u043d\u044b\u043c.  <\/p>\n<p>    \u00a0\u00a0 \u00a0\u0414\u043b\u044f \u043d\u0430\u0447\u0430\u043b\u0430 \u044f \u0440\u0430\u0437\u0431\u0435\u0440\u0443 \u043f\u0430\u0440\u0443 \u0440\u0435\u0448\u0435\u043d\u0438\u0439 \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043a\u043e\u043d\u0435\u0447\u043d\u043e \u0431\u0443\u0434\u0443\u0442 \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c, \u043e\u0442\u043c\u0435\u0447\u0443 \u0438\u0445 \u043f\u043b\u044e\u0441\u044b \u0438 \u043c\u0438\u043d\u0443\u0441\u044b, \u043d\u043e \u0442\u0430\u043a \u0434\u0435\u043b\u0430\u0442\u044c \u043d\u0435 \u043d\u0430\u0434\u043e! \u0410 \u0432 \u043a\u043e\u043d\u0446\u0435 \u043f\u043e\u043a\u0430\u0436\u0443 \u0440\u0435\u0448\u0435\u043d\u0438\u0435 \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u043c\u0435\u043d\u044f \u0432 \u043f\u0440\u0438\u043d\u0446\u0438\u043f\u0435 \u043f\u043e\u043b\u043d\u043e\u0441\u0442\u044c\u044e \u0443\u0434\u043e\u0432\u043b\u0435\u0442\u0432\u043e\u0440\u044f\u0435\u0442, \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u043d\u043e \u0432 \u0440\u0430\u043c\u043a\u0430\u0445 \u043f\u0440\u0430\u0432\u0438\u043b \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0451\u043d\u043d\u043e\u0433\u043e \u0440\u0430\u043d\u0435\u0435 \u0448\u0430\u0431\u043b\u043e\u043d\u0430 \u0438 \u043d\u0430\u0434\u0435\u044e\u0441\u044c \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u043e \u0432 \u0434\u0430\u043b\u044c\u043d\u0435\u0439\u0448\u0438\u0445 \u043f\u0440\u043e\u0435\u043a\u0442\u0430\u0445.    <\/p>\n<p>    \u00a0\u00a0 \u00a0\u0418 \u0442\u0430\u043a \u043f\u0435\u0440\u0432\u043e\u0435 \u0440\u0435\u0448\u0435\u043d\u0438\u0435, \u044d\u0442\u043e \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u043d\u043e\u0432\u043e\u0433\u043e \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440\u0430 \u0442\u0430\u0439\u043c\u0435\u0440\u0430 \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u0442\u044c \u043d\u043e\u0432\u044b\u0439 \u043f\u043e\u0442\u043e\u043a, \u0447\u0442\u043e \u043c\u043e\u0436\u0435\u0442 \u043a\u043e\u043c\u0443-\u0442\u043e \u043f\u043e\u043a\u0430\u0437\u0430\u0442\u044c\u0441\u044f \u043d\u0435 \u043e\u0447\u0435\u043d\u044c \u0445\u043e\u0440\u043e\u0448\u0435\u0439 \u0438\u0434\u0435\u0435\u0439, \u043d\u043e \u0435\u0441\u043b\u0438 \u043d\u043e\u0432\u044b\u0435 \u043f\u043e\u0442\u043e\u043a\u0438 \u0431\u0443\u0434\u0443\u0442 \u043f\u043e\u0447\u0442\u0438 \u0432\u0441\u0435\u0433\u0434\u0430 \u0441\u043f\u0430\u0442\u044c \u0438 \u043d\u0435 \u0442\u0440\u0430\u0442\u0438\u0442\u044c \u0432\u044b\u0447\u0438\u0441\u043b\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0435 \u0440\u0435\u0441\u0443\u0440\u0441\u044b, \u0442\u043e \u043d\u0430\u0432\u0435\u0440\u043d\u043e\u0435 \u0432 \u044d\u0442\u043e\u043c \u043d\u0435\u0442 \u043d\u0438\u0447\u0435\u0433\u043e \u043f\u043b\u043e\u0445\u043e\u0433\u043e. \u0410, \u0432\u0442\u043e\u0440\u043e\u0435 \u0440\u0435\u0448\u0435\u043d\u0438\u0435, \u044d\u0442\u043e \u0437\u0430\u0434\u0435\u0439\u0441\u0442\u0432\u043e\u0432\u0430\u0442\u044c \u0432\u0441\u0435\u0433\u043e \u043e\u0434\u0438\u043d \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0439 \u043f\u043e\u0442\u043e\u043a \u0434\u043b\u044f \u0432\u0441\u0435\u0445 \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440\u043e\u0432 \u0442\u0430\u0439\u043c\u0435\u0440\u0430.<\/p>\n<p>    \u00a0\u00a0 \u00a0\u0414\u043b\u044f Linux \u0432 \u0421\u0438 \u043d\u0430\u0431\u043e\u0440 \u0444\u0443\u043d\u043a\u0446\u0438\u0439 \u0438 \u0442\u0438\u043f\u043e\u0432 \u0434\u043b\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u0441 \u043f\u043e\u0442\u043e\u043a\u0430\u043c\u0438 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d \u0432 \u0444\u0430\u0439\u043b\u0435 <strong>&lt;pthread.h><\/strong>. \u041f\u0440\u0438 \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0446\u0438\u0438 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0442\u044c \u043a\u043b\u044e\u0447 <strong>-lpthread<\/strong>.  \u0421\u0438\u043d\u0445\u0440\u043e\u043d\u0438\u0437\u0430\u0446\u0438\u044f \u043f\u043e\u0442\u043e\u043a\u043e\u0432 (\u043f\u0440\u0438 \u0434\u043e\u0441\u0442\u0443\u043f\u0435 \u043a \u043e\u0431\u0449\u0435\u043c\u0443 \u0440\u0435\u0441\u0443\u0440\u0441\u0443) \u043c\u043e\u0436\u0435\u0442 \u043e\u0441\u0443\u0449\u0435\u0441\u0442\u0432\u043b\u044f\u0442\u044c\u0441\u044f \u043c\u044e\u0442\u0435\u043a\u0441\u0430\u043c\u0438 \u0438 \u0441\u0435\u043c\u0430\u0444\u043e\u0440\u0430\u043c\u0438. \u0418 \u0434\u043b\u044f \u043f\u0440\u0430\u043a\u0442\u0438\u0447\u0435\u0441\u043a\u043e\u0433\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u0432\u0441\u0451 \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u043f\u0440\u043e\u0441\u0442\u043e.<\/p>\n<p>    \u00a0\u00a0 \u00a0\u041d\u043e\u0432\u044b\u0439 \u043a\u043b\u0430\u0441\u0441 \u0442\u0430\u0439\u043c\u0435\u0440\u0430 \u044f \u0440\u0435\u0448\u0438\u043b \u043d\u0430\u0437\u0432\u0430\u0442\u044c <strong>stimer<\/strong>, \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0435\u043d\u043d\u043e \u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043e\u0447\u043d\u044b\u0439 \u0444\u0430\u0439\u043b <strong>stimer.h<\/strong> \u043f\u043e\u043b\u0443\u0447\u0438\u043b\u0441\u044f \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0433\u043e \u0432\u0438\u0434\u0430, \u0438 \u043e\u043d \u0431\u0443\u0434\u0435\u0442 \u043e\u0431\u0449\u0438\u0439 \u0434\u043b\u044f \u0432\u0441\u0435\u0445 \u0440\u0435\u0448\u0435\u043d\u0438\u0439:<\/p>\n<pre><code class=\"cpp\">#ifndef _STIMER_H_ #define _STIMER_H_  #include &lt;stdlib.h> #include \"sfuns.h\" \/\/\u0412 sfuns.h \u043f\u0440\u043e\u0441\u0442\u043e \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0451\u043d \u0442\u0438\u043f t_bool  \/\/\u0421\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0430 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u044e\u0449\u0430\u044f \u043d\u043e\u0432\u044b\u0439 \u043a\u043b\u0430\u0441\u0441 struct stimer; typedef struct stimer t_stimer;  \/\/\u0421\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0430 \u0441\u043e\u0431\u044b\u0442\u0438\u0439. typedef struct stimer_events {     void (*on_time)(t_stimer* timer);     void (*on_error)(t_stimer* timer, int* exception); } t_stimer_events;  \/\/\u041a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440\/\u0434\u0435\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440 t_stimer* stimer_create(void* parent, int* exception); void stimer_destroy(t_stimer* timer);  \/\/\u0418\u043d\u0442\u0435\u0440\u0432\u0430\u043b void stimer_set_interval(t_stimer* timer, int value);  \/\/\u0410\u043a\u0442\u0438\u0432\u0430\u0446\u0438\u044f\/\u0434\u0435\u0430\u043a\u0442\u0438\u0432\u0430\u0446\u0438\u044f \u0442\u0430\u0439\u043c\u0435\u0440\u0430 void stimer_set_active(t_stimer* timer, t_bool enable); t_bool stimer_get_active(t_stimer* timer);  \/\/\u0421\u043b\u0443\u0448\u0430\u0442\u0435\u043b\u044c \u0441\u043e\u0431\u044b\u0442\u0438\u044f void stimer_set_listener(t_stimer* timer, t_stimer_events* listener);  \/\/\u0424\u0430\u043c\u0438\u043b\u0438\u044f \u0440\u043e\u0434\u0438\u0442\u0435\u043b\u044f void stimer_set_parent(t_stimer* timer, void* parent); void* stimer_get_parent(t_stimer* timer);  #endif<\/code><\/pre>\n<p>\u0412 \u043e\u0441\u043d\u043e\u0432\u043d\u043e\u043c \u0444\u0430\u0439\u043b\u0435 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u044b (<strong>main.c<\/strong> \u0438 \u043e\u043d \u0442\u0430\u043a\u0436\u0435 \u0431\u0443\u0434\u0435\u0442 \u043e\u0431\u0449\u0438\u0439 \u0434\u043b\u044f \u0432\u0441\u0435\u0445 \u0440\u0435\u0448\u0435\u043d\u0438\u0439), \u0434\u043b\u044f \u043f\u0440\u0438\u043c\u0435\u0440\u0430, \u043f\u0440\u0430\u043a\u0442\u0438\u0447\u0435\u0441\u043a\u043e\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 \u0442\u0430\u0439\u043c\u0435\u0440\u0430 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c:<\/p>\n<pre><code class=\"cpp\">#include &lt;stdlib.h> #include &lt;stdio.h> #include &lt;time.h> #include &lt;unistd.h> #include &lt;termios.h>  #include \"sfuns.h\" #include \"stimer.h\"  \/\/\u041e\u0431\u044a\u044f\u0432\u043b\u0435\u043d\u0430 \u043f\u0430\u0440\u0430 \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440\u043e\u0432 \u0442\u0430\u0439\u043c\u0435\u0440\u0430 t_stimer* timer1;  t_stimer* timer2; \/\/\u0421\u043b\u0443\u0448\u0430\u0442\u0435\u043b\u044c \u0441\u043e\u0431\u044b\u0442\u0438\u0439 \u043e\u0442 \u0442\u0430\u0439\u043c\u0435\u0440\u0430 t_stimer_events listener;  \/\/\u0424\u0443\u043d\u043a\u0446\u0438\u0438 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u0441\u043e\u0431\u044b\u0442\u0438\u0439 void ontime_events(t_stimer* timer) {     time_t curent_time;     time(&amp;curent_time);      if(timer == timer1){         printf(\"Event timer 1 %s\",ctime(&amp;curent_time));     }     if(timer == timer2){         printf(\"Event timer 2 %s\",ctime(&amp;curent_time));     } }  void onerror_events(t_stimer* timer, int* exception) {     if(timer == timer1){         printf(\"Error timer 1 %d\\n\", *exception);     }     if(timer == timer2){         printf(\"Error timer 2 %d\\n\", *exception);     } }  int main(int args, char** argv) {     unsigned char key;     int err;      \/\/\u041f\u0440\u0438\u0441\u0432\u043e\u0435\u043d\u0438\u0435 \u0441\u043b\u0443\u0448\u0430\u0442\u0435\u043b\u044e \u0441\u043e\u0431\u044b\u0442\u0438\u0439 \u0435\u0433\u043e \u0444\u0443\u043d\u043a\u0446\u0438\u0439 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u043e\u0432     listener.on_time = ontime_events;     listener.on_error = onerror_events;      \/\/\u0418\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u0432 \u0442\u0430\u0439\u043c\u0435\u0440\u0430. \u0422.\u043a. \u0440\u043e\u0434\u0438\u0442\u0435\u043b\u044c \u043d\u0430\u043c \u0432     \/\/\u0434\u0430\u043d\u043d\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u043d\u0435 \u043d\u0443\u0436\u0435\u043d, \u0442\u043e \u043f\u0435\u0440\u0432\u044b\u043c \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u043c \u043f\u0438\u0448\u0435\u043c NULL      timer1 = stimer_create(NULL,&amp;err);     if(timer1 == NULL){         printf(\"Ceate timer1. Error number: %d\\n\",err);         return 0;     }     timer2 = stimer_create(NULL,&amp;err);     if(timer2 == NULL){         printf(\"Ceate timer2. Error number: %d\\n\",err);         stimer_destroy(timer1);         return 0;     }      \/\/\u0420\u0435\u0433\u0438\u0441\u0442\u0440\u0430\u0446\u0438\u044f \u0441\u043b\u0443\u0448\u0430\u0442\u0435\u043b\u044f     stimer_set_listener(timer1,&amp;listener);     stimer_set_listener(timer2,&amp;listener);      \/\/\u0423\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0430 \u043f\u0435\u0440\u0438\u043e\u0434\u0438\u0447\u043d\u043e\u0441\u0442\u0438 \u0440\u0430\u0431\u043e\u0442\u044b \u0442\u0430\u0439\u043c\u0435\u0440\u043e\u0432     \/\/\u0415\u0441\u043b\u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0432\u0430\u0442\u044c \u0444\u0443\u043d\u043a\u0446\u0438\u044e sleep, \u0442\u043e \u0438\u043d\u0442\u0435\u0440\u0432\u0430\u043b \u0431\u0443\u0434\u0435\u0442 \u0437\u0430\u0434\u0430\u0432\u0430\u0442\u044c\u0441\u044f \u0432 \u0441\u0435\u043a\u0443\u043d\u0434\u0430\u0445.     \/\/\u0414\u043b\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u0438 nanosleep, \u0432 \u043f\u0440\u0438\u043c\u0435\u0440\u0430\u0445, \u0438\u043d\u0442\u0435\u0440\u0432\u0430\u043b \u0431\u0443\u0434\u0435\u0442 \u0437\u0430\u0434\u0430\u0432\u0430\u0442\u044c\u0441\u044f \u0432 \u043c\u0438\u043b\u043b\u0438\u0441\u0435\u043a\u0443\u043d\u0434\u0430\u0445.     stimer_set_interval(timer1, 3000);     stimer_set_interval(timer2, 5000);      stimer_set_active(timer1, true);     stimer_set_active(timer2, true);      \/\/\u041e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0430 \u043a\u043b\u0430\u0432\u0438\u0430\u0442\u0443\u0440\u044b     do {         key = sgetch();         printf(\"key: %d\\n\",key);         if(key==49){ \/\/1             stimer_set_active(timer1, false);             printf(\"timer1 active false\\n\");         }         if(key==50){ \/\/2             stimer_set_active(timer1, true);             printf(\"timer1 active true\\n\");         }         if(key==51){ \/\/3             stimer_set_active(timer2, false);             printf(\"timer2 active false\\n\");         }         if(key==52){ \/\/4             stimer_set_active(timer2, true);             printf(\"timer2 active true\\n\");         }     } while (key!=27); \/\/ESC      stimer_destroy(timer1);     stimer_destroy(timer2);      return 0; }<\/code><\/pre>\n<p>\u041f\u0435\u0440\u0432\u043e\u0435 \u0440\u0435\u0448\u0435\u043d\u0438\u0435 \u043e\u043f\u0440\u043e\u0431\u043e\u0432\u0430\u043b \u043d\u0430 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 <strong>sleep().<\/strong>  \u041c\u0430\u043a\u0441\u0438\u043c\u0430\u043b\u044c\u043d\u0430\u044f \u0447\u0430\u0441\u0442\u043e\u0442\u0430 \u043e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u044f \u0434\u0430\u043d\u043d\u043e\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u043e\u0434\u043d\u0430 \u0441\u0435\u043a\u0443\u043d\u0434\u0430, \u0447\u0442\u043e \u043c\u043e\u0436\u0435\u0442  \u0431\u044b\u0442\u044c \u0438 \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u044b\u043c \u0434\u043b\u044f \u0440\u0435\u0448\u0435\u043d\u0438\u044f \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0451\u043d\u043d\u043e\u0433\u043e \u043a\u0440\u0443\u0433\u0430 \u0437\u0430\u0434\u0430\u0447, \u043d\u043e \u0445\u043e\u0442\u0435\u043b\u043e\u0441\u044c \u0431\u044b  \u0431\u043e\u043b\u044c\u0448\u0435\u0433\u043e, \u0438 \u0442\u0430\u043a \u0441\u043c. \u0438\u0441\u0445\u043e\u0434\u043d\u044b\u0439 \u0444\u0430\u0439\u043b \u0441 \u043a\u043e\u043c\u043c\u0435\u043d\u0442\u0430\u0440\u0438\u044f\u043c\u0438:<\/p>\n<pre><code class=\"cpp\">#include &lt;stdlib.h> #include &lt;unistd.h> #include &lt;errno.h> #include &lt;pthread.h>  #include \"sfuns.h\" #include \"stimer.h\"  \/\/\u0422.\u043a. \u0434\u043e\u0441\u0442\u0443\u043f \u0434\u043e \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u0430 \u0441\u043e\u0431\u044b\u0442\u0438\u0439 \u0432\u043e\u0437\u043c\u043e\u0436\u0435\u043d \u0438\u0437 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u0438\u0445 \u043f\u043e\u0442\u043e\u043a\u043e\u0432, \/\/\u0442\u043e \u0434\u043b\u044f \u0441\u0438\u043d\u0445\u0440\u043e\u043d\u0438\u0437\u0430\u0446\u0438\u0438 \u043f\u043e\u043d\u0430\u0434\u043e\u0431\u0438\u043b\u0441\u044f \u043c\u044e\u0442\u0435\u043a\u0441  static pthread_mutex_t mutex;  \/\/\u0414\u043b\u044f \u043e\u0434\u043d\u043e\u0440\u0430\u0437\u043e\u0432\u043e\u0439 \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u043c\u044c\u044e\u0442\u0435\u043a\u0441\u0430 \u0438 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u043f\u0430\u0442\u0435\u0440\u043d\u0430 \"\u043e\u0434\u0438\u043d\u043e\u0447\u043a\u0430\" \/\/\u043f\u0440\u043e\u0441\u0442\u043e \u0432\u0432\u0435\u043b \u043b\u043e\u043a\u0430\u043b\u044c\u043d\u0443\u044e \u0433\u043b\u043e\u0431\u0430\u043b\u044c\u043d\u0443\u044e \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0443\u044e  static t_bool single_init = false;  \/\/\u041f\u043e\u0434\u0441\u0447\u0451\u0442 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u0430 \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440\u043e\u0432 \u0442\u0430\u0439\u043c\u0435\u0440\u0430 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c \u0434\u043b\u044f \u0442\u043e\u0433\u043e,  \/\/\u0447\u0442\u043e \u0431\u044b \u0432 \u0434\u0435\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440\u0435 \u043f\u043e\u043d\u0438\u043c\u0430\u0442\u044c, \u0447\u0442\u043e \u0443 \u043d\u0430\u0441 \u0435\u0449\u0451 \u043a\u0442\u043e-\u0442\u043e \u043e\u0441\u0442\u0430\u043b\u0441\u044f \u0438\u043b\u0438 \u043d\u0435\u0442. static int n_timers = 0;  \/\/\u0421\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0430 \u043a\u043b\u0430\u0441\u0441\u0430 \u0441 \u043f\u0440\u0438\u0432\u0430\u0442\u043d\u044b\u043c\u0438 \u043f\u043e\u043b\u044f\u043c\u0438 struct stimer {     int interval;      \/\/\u041f\u0435\u0440\u0438\u043e\u0434\u0438\u0447\u043d\u043e\u0441\u0442\u044c \u0440\u0430\u0431\u043e\u0442\u044b     t_bool enable;     \/\/\u0421\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435 \u0430\u043a\u0442\u0438\u0432\u043d\u043e\u0441\u0442\u0438      pthread_t tid;     \/\/\u0418\u0434\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440 \u043f\u043e\u0442\u043e\u043a\u0430     t_stimer_events* listener; \/\/\u0421\u043b\u0443\u0448\u0430\u0442\u0435\u043b\u044c \u0441\u043e\u0431\u044b\u0442\u0438\u0439     void* parent;              \/\/\u0427\u044c\u0438\u0445 \u0440\u043e\u0434\u0430 \u0431\u0443\u0434\u0435\u0442 };  \/\/\u0424\u0443\u043a\u0446\u0438\u044f \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u043e\u0433\u043e \u043f\u043e\u0442\u043e\u043a\u0430 void* execute_thread(void* arg) {     \/\/\u041f\u0435\u0440\u0435\u0434\u0430\u0447\u0430 \u0443\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u044f \u043d\u0430 \u044d\u043a\u0437\u0435\u043c \u0441\u043e\u0437\u0434\u0430\u043d\u043d\u043e\u0433\u043e \u043e\u0431\u044a\u0435\u043a\u0442\u0430 \u0442\u0430\u0439\u043c\u0435\u0440\u0430     t_stimer* timer = (t_stimer*) arg;          \/\/\u0412\u043a\u043b\u044e\u0447\u0430\u0435\u0442 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u043d\u0435\u043c\u0435\u0434\u043b\u0435\u043d\u043d\u043e\u0433\u043e \u0437\u0430\u0432\u0435\u0440\u0448\u0435\u043d\u0438\u044f \u043f\u043e\u0442\u043e\u043a\u0430     pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL);      do {         \/\/\u041e\u0442\u043f\u0440\u0430\u0432\u043b\u044f\u0435\u0442 \u043f\u043e\u0442\u043e\u043a \u0432 \u0441\u043e\u043d \u043d\u0430 \u0437\u0430\u0434\u0430\u043d\u043d\u044b\u0439 \u0438\u043d\u0442\u0435\u0440\u0432\u0430\u043b (\u0432 \u0441\u0435\u043a\u0443\u043d\u0434\u0430\u0445)         sleep(timer->interval);                   \/\/\u0422\u0430\u043a \u043a\u0430\u043a \u0434\u043b\u044f \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u0441\u043e\u0431\u044b\u0442\u0438\u0439, \u0434\u043b\u044f \u0432\u0441\u0435\u0445 \u043f\u043e\u0442\u043e\u043a\u043e\u0432, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f          \/\/\u043e\u0434\u043d\u0430 \u0438 \u0442\u0430\u0436\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u044f, \u0442\u043e \u0434\u043e\u0441\u0442\u0443\u043f \u043a \u043d\u0435\u0439 \u0441\u0438\u043d\u0445\u0440\u043e\u043d\u0438\u0437\u0438\u0440\u0443\u0435\u043c \u043c\u044e\u0442\u0435\u043a\u0441\u043e\u043c         pthread_mutex_lock(&amp;mutex);         timer->listener->on_time(timer);         pthread_mutex_unlock(&amp;mutex);      \/\/\u0422\u0430\u043a \u043a\u0430\u043a \u043f\u043e\u0442\u043e\u043a \u043c\u043e\u0436\u0435\u0442 \u0437\u0430\u0432\u0435\u0440\u0448\u0430\u0442\u044c\u0441\u044f \u043d\u0435\u043c\u0435\u0434\u043b\u0435\u043d\u043d\u043e,     \/\/\u0442\u043e \u043a\u0430\u043a\u0438\u0445-\u0442\u043e \u0443\u0441\u043b\u043e\u0432\u0438\u0439 \u0434\u043b\u044f \u0432\u044b\u0445\u043e\u0434\u0430 \u0438\u0437 \u0446\u0438\u043a\u043b\u0430 \u043d\u0435 \u0442\u0440\u0435\u0431\u0443\u0435\u0442\u0441\u044f              } while(1);   }  \/\/\u0424\u0443\u043d\u043a\u0446\u0438\u044f \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440 t_stimer* stimer_create(void* parent, int* exception) {     int status;      \/\/\u0412\u044b\u0434\u0435\u043b\u044f\u0435\u043c \u043f\u0430\u043c\u044f\u0442\u044c \u043f\u043e\u0434 \u043d\u043e\u0432\u044b\u0439 \u043e\u0431\u044a\u0435\u043a\u0442     t_stimer* new_stimer = malloc(sizeof(t_stimer));     \/\/\u041f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u043c, \u0447\u0442\u043e \u0432\u0441\u0451 \u0437\u0430\u043c\u0435\u0447\u0430\u0442\u0435\u043b\u044c\u043d\u043e \u0438\u043b\u0438 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u043c\u0441\u044f \u0441 \u043a\u043e\u0434\u043e\u043c \u043e\u0448\u0438\u0431\u043a\u0438     if(new_stimer == NULL){         *exception = errno;         return NULL;     }       \/\/\u0418\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0438\u0440\u0443\u0435\u043c \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0435 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u044b-\u0442\u0430\u0439\u043c\u0435\u0440\u0430     new_stimer->enable = false;     new_stimer->interval = 1;     new_stimer->parent = parent;          n_timers++;          \/\/\u041e\u0434\u043d\u043e\u043a\u0440\u0430\u0442\u043d\u0430\u044f \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u043e\u0431\u0449\u0435\u0433\u043e \u043c\u044e\u0442\u0435\u043a\u0441\u0430     if(single_init == false) {        status = pthread_mutex_init(&amp;mutex,NULL);        if(0!=status){            free(new_stimer);            *exception = status;            return NULL;        }        single_init = true;          }          return new_stimer; }  \/\/\u0424\u0443\u043d\u043a\u0446\u0438\u044f \u0434\u0435\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440 void stimer_destroy(t_stimer* timer) {     if(n_timers > 0){         if(timer->enable == true){             pthread_cancel(timer->tid);             timer->enable = false;         }         free(timer);         timer = NULL;         n_timers--;         if(n_timers == 0){             pthread_mutex_destroy(&amp;mutex);             single_init = false;         }     } }  \/\/\u0412\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435 \u0438 \u0432\u044b\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435 \u0442\u0430\u0439\u043c\u0435\u0440\u0430 void stimer_set_active(t_stimer* timer, t_bool enable) {      int status;      if((timer->enable == false) &amp;&amp; (enable == true)){         status = pthread_create(&amp;timer->tid,0,execute_thread,timer);         if(0!=status){             timer->listener->on_error(timer,&amp;status);         }     }     if((timer->enable == true) &amp;&amp; (enable == false)){         status = pthread_cancel(timer->tid);         if(0!=status){             timer->listener->on_error(timer,&amp;status);         }     }     timer->enable = enable; } \/\/\u0412\u043e \u0432\u0440\u0435\u043c\u044f \u0432\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u044f \u0438 \u0432\u044b\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u044f \u0442\u0430\u0439\u043c\u0435\u0440\u0430 \u0441\u043e\u0437\u0434\u0430\u0451\u0442\u0441\u044f \u0438 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0435\u043d\u043d\u043e \/\/\u0443\u043d\u0438\u0447\u0442\u043e\u0436\u0430\u0435\u0442 \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0439 \u043f\u043e\u0442\u043e\u043a. \u041d\u0430 \u044d\u0442\u043e \u0442\u0440\u0430\u0442\u044f\u0442\u0441\u044f \u0440\u0435\u0441\u0443\u0440\u0441\u044b, \u0447\u0442\u043e \u043d\u0435 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u0435\u0442 \/\/\u043f\u0440\u0435\u0434\u044a\u044f\u0432\u043b\u044f\u0435\u043c\u044b\u043c \u043a \u0442\u0430\u0439\u043c\u0435\u0440\u0443 \u0442\u0440\u0435\u0431\u043e\u0432\u0430\u043d\u0438\u044f\u043c. \u0422\u0430\u043a\u0430\u044f \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u0438\u043c\u0435\u0435\u0442 \u043c\u0435\u0441\u0442\u043e \u0431\u044b\u0442\u044c \/\/\u0442\u043e\u043b\u044c\u043a\u043e \u043f\u0440\u0438 \u0443\u0441\u043b\u043e\u0432\u0438\u0438 \u043d\u0435 \u0447\u0430\u0441\u0442\u043e\u0439 \u0438\u043b\u0438 \u0435\u0434\u0438\u043d\u043e\u0432\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u0439 \u0430\u043a\u0442\u0438\u0432\u0430\u0446\u0438\u0438 \u0442\u0430\u0439\u043c\u0435\u0440\u0430.  \/\/\u0414\u0430\u043b\u0435\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \"\u0441\u0435\u0442\u0442\u0435\u0440\u044b\" \u0438 \"\u0433\u0435\u0442\u0442\u0435\u0440\u044b\" \u0434\u043b\u044f \u0434\u043e\u0441\u0442\u0443\u043f\u0430 \u043a \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u043c \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u044b  void stimer_set_interval(t_stimer* timer, int value) {     timer->interval =value; }  t_bool stimer_get_active(t_stimer* timer) {     return timer->enable; }  void stimer_set_listener(t_stimer* timer, t_stimer_events* listener) {     timer->listener = listener; }  void stimer_set_parent(t_stimer* timer, void* parent) {     timer->parent = parent; }  void* stimer_get_parent(t_stimer* timer) {     return timer->parent; }<\/code><\/pre>\n<p>\u00a0\u00a0\u00a0 \u041f\u043e\u043b\u0443\u0447\u0438\u043b\u0430\u0441\u044c  \u043e\u0442\u043a\u0440\u043e\u0432\u0435\u043d\u043d\u0430\u044f &#171;\u0436\u0435\u0441\u0442\u044c&#187;. \u0421\u0447\u0438\u0442\u0430\u044e, \u0447\u0442\u043e &#171;\u043a\u0440\u044d\u0448\u0438\u0442\u044c&#187; \u043f\u043e\u0442\u043e\u043a\u0438 \u0438 \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u0442\u044c \u0438\u0445 \u0437\u0430\u043d\u043e\u0432\u043e  \u043d\u0435 \u043e\u0447\u0435\u043d\u044c \u0445\u043e\u0440\u043e\u0448\u0430\u044f \u0438\u0434\u0435\u044f. \u0420\u0435\u0448\u0435\u043d\u0438\u0435 \u043f\u0440\u043e\u0441\u0442\u043e\u0435, \u043d\u043e \u043d\u0430 \u044d\u0442\u043e\u043c \u0432\u0441\u0435 \u043f\u043b\u044e\u0441\u044b \u0438  \u0437\u0430\u043a\u0430\u043d\u0447\u0438\u0432\u0430\u044e\u0442\u0441\u044f \u043f\u043e\u044d\u0442\u043e\u043c\u0443 &#8212; &#171;\u0432 \u0442\u043e\u043f\u043a\u0443&#187;. <\/p>\n<p>\u00a0\u00a0\u00a0 \u0421\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0435  \u0440\u0435\u0448\u0435\u043d\u0438\u0435 &#8212; \u044d\u0442\u043e \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440\u0430 \u0442\u0430\u0439\u043c\u0435\u0440\u0430 \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0442\u044c \u0447\u0435\u0440\u0435\u0437 \u0437\u0430\u0434\u0430\u043d\u043d\u044b\u0439  \u043f\u043e\u0441\u0442\u043e\u044f\u043d\u043d\u044b\u0439 \u0438\u043d\u0442\u0435\u0440\u0432\u0430\u043b \u0432\u0440\u0435\u043c\u0435\u043d\u0438 \u043f\u0435\u0440\u0438\u043e\u0434 \u043e\u0436\u0438\u0434\u0430\u043d\u0438\u044f, \u0430 \u043a\u043e\u0433\u0434\u0430 \u043f\u0435\u0440\u0438\u043e\u0434 \u043e\u0436\u0438\u0434\u0430\u043d\u0438\u044f  \u043f\u0440\u0435\u0432\u044b\u0448\u0435\u043d \u0444\u043e\u0440\u043c\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0441\u043e\u0431\u044b\u0442\u0438\u0435.\u00a0<\/p>\n<p>\u00a0\u00a0 \u00a0\u041f\u043b\u044e\u0441\u044b  \u0432 \u0442\u043e\u043c, \u0447\u0442\u043e \u0434\u043b\u044f \u0442\u0430\u043a\u043e\u0439 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u043d\u0435 \u0442\u0440\u0435\u0431\u0443\u0435\u0442\u0441\u044f \u0431\u043e\u043b\u0435\u0435 \u043e\u0434\u043d\u043e\u0433\u043e  \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0433\u043e \u043f\u043e\u0442\u043e\u043a\u0430, \u0432\u0441\u0451 \u043c\u043e\u0436\u0435\u0442 \u043a\u0440\u0443\u0442\u0438\u0442\u044c\u0441\u044f \u0432 \u043e\u0434\u043d\u043e\u043c \u0446\u0438\u043a\u043b\u0435 \u0438,  \u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e \u043d\u0435 \u0442\u0440\u0435\u0431\u0443\u0435\u0442\u0441\u044f \u043c\u044e\u0442\u0435\u043a\u0441\u0430, \u0442\u0430\u043a \u043a\u0430\u043a \u043d\u0435 \u043d\u0430\u0434\u043e \u0441\u0438\u043d\u0445\u0440\u043e\u043d\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u0442\u044c  \u043f\u043e\u0442\u043e\u043a\u0438.<\/p>\n<p>\u00a0\u00a0\u00a0 \u0414\u0430\u043d\u043d\u043e\u0435 \u0440\u0435\u0448\u0435\u043d\u0438\u0435 \u043e\u043f\u0440\u043e\u0431\u043e\u0432\u0430\u043b \u0441 \u0444\u0443\u043d\u043a\u0446\u0438\u0435\u0439 <strong>nanosleep(). <\/strong>\u0418\u0441\u0445\u043e\u0434\u044f  \u0438\u0437 \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u044f, \u0434\u0430\u043d\u043d\u0430\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u043c\u043e\u0436\u0435\u0442 \u043e\u0431\u0435\u0441\u043f\u0435\u0447\u0438\u0432\u0430\u0442\u044c \u0437\u0430\u0434\u0435\u0440\u0436\u043a\u0438 \u0432 \u043d\u0430\u043d\u043e\u0441\u0435\u043a\u0443\u043d\u0434\u0430\u0445,  \u0430 \u0432\u043e\u0442 \u0444\u0430\u043a\u0442\u0438\u0447\u0435\u0441\u043a\u0430\u044f \u0442\u043e\u0447\u043d\u043e\u0441\u0442\u044c \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u0442\u0441\u044f \u0432 \u043c\u0438\u043b\u043b\u0438\u0441\u0435\u043a\u0443\u043d\u0434\u0430\u0445, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u0437\u0430\u0434\u0430\u043d\u0438\u0435  \u043f\u0435\u0440\u0435\u043c\u043d\u043d\u043e\u0439 <strong>value<\/strong> \u0434\u043b\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u0438 <strong>stimer_set_interval()<\/strong> \u0432\u044b\u0431\u0440\u0430\u043d\u043e \u0432 \u043c\u0438\u043b\u043b\u0438\u0441\u0435\u043a\u0443\u043d\u0434\u0430\u0445.<\/p>\n<p>\u00a0\u00a0\u00a0 \u0420\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u0438\u043c\u0435\u0435\u0442 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0439 \u0432\u0438\u0434:<\/p>\n<pre><code class=\"cpp\">#include &lt;stdlib.h> #include &lt;stdio.h> #include &lt;errno.h> #include &lt;unistd.h> #include &lt;pthread.h> #include &lt;time.h>  #include \"sfuns.h\" #include \"stimer.h\"  static t_bool single_init = false; static pthread_t tid = 0; static t_bool terminate = false;  static int n_timers = 0;  struct stimer {     int interval;      struct timespec time_before;     struct timespec time_after;      t_bool enable;     t_stimer_events* listener;     void* parent; };  static t_stimer** timers;  void* execute_thread(void* arg) {     int i;     int interval;      \/\/\u041f\u0435\u0440\u0438\u043e\u0434 \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u044f \u0432\u0440\u0435\u043c\u0435\u043d\u0438 \u0437\u0430\u0434\u0430\u0451\u0442\u0441\u044f \u0441 \u0442\u043e\u0447\u043d\u043e\u0441\u0442\u044c\u044e \u0432 10\u043c\u0441.     \/\/\u041a\u043e\u043d\u0442\u0440\u043e\u043b\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0432 \u0434\u0430\u043d\u043d\u043e\u0439 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u0442\u0430\u0439\u043c\u0435\u0440\u0430 \u0442\u043e\u0447\u043d\u043e\u0441\u0442\u044c \u0432 1\u043c\u0441 \u043d\u0435 \u0438\u043c\u0435\u0435\u0442 \u0441\u043c\u044b\u0441\u043b\u0430,     \/\/\u0442\u0430\u043a \u043a\u0430\u043a \u044d\u0442\u043e \u043f\u043e\u0447\u0442\u0438 \u043d\u0435 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e \u0438, \u043a\u0430\u043a \u043f\u0440\u0430\u0432\u0438\u043b\u043e, \u043d\u0435 \u0442\u0440\u0435\u0431\u0443\u0435\u0442\u0441\u044f,     \/\/\u0430 \u043a\u0440\u0443\u0442\u0438\u0442\u044c \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0443 \u0442\u0430\u0439\u043c\u0435\u0440\u043e\u0432 \u0441 \u0442\u0430\u043a\u043e\u0439 \u0447\u0430\u0441\u0442\u043e\u0442\u043e\u0439 \u0442\u043e\u043b\u044c\u043a\u043e \"\u043f\u043e\u0436\u0435\u0440\u0430\u0442\u044c\" \u0440\u0435\u0441\u0443\u0440\u0441\u044b \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u043e\u0440\u0430.      struct timespec sleep_period = {0,9999999}; \/\/\u041f\u0435\u0440\u0438\u043e\u0434, \u043f\u043e\u0447\u0442\u0438 10 \u043c\u0441      do {         for(i=0;i&lt;n_timers;i++){             if(timers[i]->enable == false){                 \/\/\u0415\u0441\u043b\u0438 \u0442\u0430\u0439\u043c\u0435\u0440 \u043d\u0435 \u0430\u043a\u0442\u0438\u0432\u043d\u044b\u0439, \u0442\u043e \u043f\u0440\u0438\u0441\u0432\u0430\u0438\u0432\u0430\u0435\u043c \u0435\u043c\u0443 \u043d\u0430\u0447\u0430\u043b\u044c\u043d\u043e\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435                 clock_gettime(CLOCK_REALTIME, &amp;timers[i]->time_before);             }         }         \/\/\u0417\u0430\u0441\u044b\u043f\u0430\u0435\u043c \u043d\u0430 10\u043c\u0441         nanosleep(&amp;sleep_period , NULL);          for(i=0;i&lt;n_timers;i++){             if(timers[i]->enable == true){                 \/\/\u041f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u0442\u0435\u043a\u0443\u0449\u0435\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0432\u0440\u0435\u043c\u0435\u043d\u0438.                 clock_gettime(CLOCK_REALTIME, &amp;timers[i]->time_after);                 \/\/\u0412\u044b\u0447\u0438\u0441\u043b\u044f\u0435\u043c \u043f\u0440\u043e\u0448\u0435\u0434\u0448\u0435\u0435 \u0432\u0440\u0435\u043c\u044f \u043e\u0436\u0438\u0434\u0430\u043d\u0438\u044f                 interval = ((timers[i]->time_after.tv_sec-timers[i]->time_before.tv_sec)*1000000000                              +timers[i]->time_after.tv_nsec-timers[i]->time_before.tv_nsec)\/1000000;                  \/\/\u041f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u043c \u0443\u0441\u043b\u043e\u0432\u0438\u0435, \u0435\u0441\u043b\u0438 \u041e\u041a, \u0442\u043e \u043e\u0431\u043d\u043e\u0432\u043b\u044f\u0435\u043c \u0432\u0440\u0435\u043c\u044f \u0438 \u0444\u043e\u0440\u043c\u0438\u0440\u0443\u0435\u043c \u0441\u043e\u0431\u044b\u0442\u0438\u0435                 if(interval >= timers[i]->interval){                     clock_gettime(CLOCK_REALTIME, &amp;timers[i]->time_before);                     timers[i]->listener->on_time(timers[i]);                 }             }         }      } while (terminate == false); }  t_stimer* stimer_create(void* parent, int* exception) {     int status;      t_stimer* new_stimer = malloc(sizeof(t_stimer));     if(new_stimer == NULL){         *exception = errno;         return NULL;     }     new_stimer->parent = parent;     new_stimer->interval = 1000;     new_stimer->enable = false;     new_stimer->listener = NULL;     clock_gettime(CLOCK_REALTIME,&amp;new_stimer->time_before);      n_timers++;     timers = (t_stimer**)realloc(timers, n_timers*sizeof(t_stimer*));      timers[n_timers-1] = new_stimer;      if(single_init == false){        terminate = false;         status = pthread_create(&amp;tid,0,execute_thread,NULL);        if(0!=status){            *exception = status;            n_timers=0;            free(timers);            free(new_stimer);            new_stimer = NULL;            return NULL;        }        single_init = true;     }     return new_stimer; }  void stimer_destroy(t_stimer* timer) {     int i;     int j;      if(n_timers > 0){         for(i=0;i&lt;n_timers;i++){             if(timer == timers[i]){                 for(j=i;j&lt;(n_timers-1);j++){                     timers[j]=timers[j+1];                 }                 timers = (t_stimer**)realloc(timers, (n_timers-1)*sizeof(t_stimer*));                 n_timers--;                 break;             }         }         if(n_timers == 0){             terminate = true;             pthread_join(tid,NULL);             single_init = false;             timers = NULL;         }     }     free(timer);     timer = NULL; }  void stimer_set_interval(t_stimer* timer, int value) {     timer->interval = value; }  void stimer_set_active(t_stimer* timer, t_bool enable) {     timer->enable = enable; }  t_bool stimer_get_active(t_stimer* timer) {     return timer->enable; }  void stimer_set_listener(t_stimer* timer, t_stimer_events* listener) {     timer->listener = listener; }  void stimer_set_parent(t_stimer* timer, void* parent) {     timer->parent = parent; } void* stimer_get_parent(t_stimer* timer) {     return timer->parent; }<\/code><\/pre>\n<p>\u00a0\u00a0\u00a0 \u0423\u0436\u0435  \u043b\u0443\u0447\u0448\u0435, \u043d\u043e \u0432 \u0434\u0430\u043d\u043d\u043e\u0439 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u0441\u0430\u043c\u044b\u0439 \u0431\u043e\u043b\u044c\u0448\u043e\u0439 \u043c\u0438\u043d\u0443\u0441 \u044d\u0442\u043e \u043f\u043e\u0441\u0442\u043e\u044f\u043d\u043d\u0430\u044f \u043f\u0443\u0441\u0442\u0430\u044f  \u043f\u0440\u043e\u043a\u0440\u0443\u0442\u043a\u0430 \u043f\u043e\u0442\u043e\u043a\u0430 \u0441 \u0431\u043e\u043b\u044c\u0448\u043e\u0439 \u0447\u0430\u0441\u0442\u043e\u0442\u043e\u0439, \u0430 \u0442\u0440\u0430\u0442\u0438\u0442\u044c \u043d\u0430 \u0431\u0435\u0437\u0434\u0435\u043b\u044c\u043d\u0438\u043a\u043e\u0432, \u043f\u0443\u0441\u0442\u044c  \u0434\u0430\u0436\u0435 \u0432 \u043f\u0438\u043a\u0435, 0.5% \u043e\u0442 CPU (\u043f\u043e\u043a\u0430\u0437\u0430\u043d\u0438\u044f <strong>htop<\/strong>) \u044d\u0442\u043e \u043a\u0430\u043a-\u0442\u043e \u0434\u043e\u0440\u043e\u0433\u043e\u0432\u0430\u0442\u043e. \u0422\u0430\u043a, \u0447\u0442\u043e \u0442\u0430\u043a \u0434\u0435\u043b\u0430\u0442\u044c \u0442\u043e\u0436\u0435 \u043d\u0435 \u0433\u043e\u0434\u0438\u0442\u0441\u044f.<\/p>\n<p>\u00a0\u00a0\u00a0 \u0410\u043b\u0438\u0437\u0438\u0440\u0443\u044f \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u043d\u044b\u0439 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u0440\u0435\u0448\u0438\u043b \u0437\u0430\u0434\u0430\u0447\u0443 \u0442\u0430\u0439\u043c\u0435\u0440\u0430 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c:<\/p>\n<ol>\n<li>\n<p>\u0414\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440\u0430 \u0442\u0430\u0439\u043c\u0435\u0440\u0430 \u0441\u043e\u0437\u0434\u0430\u0451\u0442\u0441\u044f \u0441\u0432\u043e\u0439 \u0438\u043d\u0434\u0438\u0432\u0438\u0434\u0443\u0430\u043b\u044c\u043d\u044b\u0439 \u043f\u043e\u0442\u043e\u043a.<\/p>\n<\/li>\n<li>\n<p>\u0414\u043b\u044f \u0437\u0430\u0434\u0435\u0440\u0436\u043a\u0438 \u043f\u043e\u0442\u043e\u043a\u043e\u0432 \u043d\u0430 \u0437\u0430\u0434\u0430\u043d\u043d\u044b\u0439 \u0438\u043d\u0442\u0435\u0440\u0432\u0430\u043b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u044f <strong>nanosleep()<\/strong>. \u0422\u043e\u0447\u043d\u043e\u0441\u0442\u044c \u0438\u043d\u0442\u0435\u0440\u0432\u0430\u043b\u0430 \u0432 \u043c\u0438\u043b\u043b\u0438\u0441\u0435\u043a\u0443\u043d\u0434\u0443 \u0431\u043e\u043b\u0435\u0435 \u0447\u0435\u043c \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u0430 \u0434\u043b\u044f \u0440\u0435\u0448\u0435\u043d\u0438\u044f, \u044f \u043d\u0435 \u043f\u043e\u0431\u043e\u044e\u0441\u044c \u043f\u0440\u0435\u0434\u043f\u043e\u043b\u043e\u0436\u0438\u0442\u044c, 90% \u0437\u0430\u0434\u0430\u0447.\u00a0<\/p>\n<\/li>\n<li>\n<p>\u0427\u0442\u043e  \u0431\u044b \u0442\u0430\u0439\u043c\u0435\u0440 \u0432 \u0432\u044b\u043a\u043b\u044e\u0447\u0435\u043d\u043d\u043e\u043c \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0438 \u043d\u0435 \u0442\u0440\u0430\u0442\u0438\u043b \u0440\u0435\u0441\u0443\u0440\u0441\u044b \u0438 \u0443\u043c\u0435\u043b \u0441\u043f\u0430\u0442\u044c  \u043d\u0435\u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u043d\u043e\u0435 \u0432\u0440\u0435\u043c\u044f, \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u043f\u043e\u0442\u043e\u043a\u0430 \u0432\u0432\u0451\u043b \u0442\u0430\u043a \u043d\u0430\u0437\u044b\u0432\u0430\u0438\u0432\u0430\u0435\u043c\u0443\u044e  &#171;\u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0443\u044e \u0443\u0441\u043b\u043e\u0432\u0438\u044f&#187;.<\/p>\n<\/li>\n<li>\n<p>\u041d\u0435\u043c\u0435\u0434\u043b\u0435\u043d\u043d\u044b\u0439 \u0441\u0431\u043e\u0441 \u0442\u0430\u0439\u043c\u0435\u0440\u0430 \u0438 \u0432\u044b\u0445\u043e\u0434 \u0438\u0437 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 <strong>nanosleep() <\/strong>\u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u043d \u0447\u0435\u0440\u0435\u0437<strong> <\/strong>\u043e\u0442\u043f\u0440\u0430\u0432\u043a\u0443 \u0441\u0438\u0433\u043d\u0430\u043b\u0430 <strong>SIGUSR1<\/strong> \u0438\u043b\u0438 <strong>SIGUSR2<\/strong> \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0435\u043c\u0443 \u043f\u043e\u0442\u043e\u043a\u0443. <\/p>\n<\/li>\n<\/ol>\n<p>\u0422\u043e,\u0447\u0442\u043e \u043f\u043e\u043b\u0443\u0447\u0438\u043b\u043e\u0441\u044c:<\/p>\n<pre><code class=\"cpp\">#include &lt;stdlib.h> #include &lt;unistd.h> #include &lt;errno.h> #include &lt;pthread.h> #include &lt;signal.h>  #include \"sfuns.h\" #include \"stimer.h\"  \/\/\u041c\u044c\u044e\u0442\u0435\u043a\u0441 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c \u0434\u043b\u044f \u0441\u0438\u043d\u0445\u0440\u043e\u043d\u0438\u0437\u0430\u0446\u0438\u0438 \u0434\u043e\u0441\u0442\u0443\u043f\u0430 \u043a \u043e\u0431\u0449\u0438\u043c \u0440\u0435\u0441\u0443\u0440\u0441\u0430\u043c static pthread_mutex_t mutex;  \/\/\u041f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0430\u044f \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u0430 \u0434\u043b\u044f \u043e\u0434\u043d\u043e\u043a\u0440\u0430\u0442\u043d\u043e\u0439 \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0445 \u0432 \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440\u0435 static t_bool single_init = false;  static int n_timers = 0;  struct stimer {     \/\/\u0421\u0432\u043e\u0439\u0441\u0442\u0432\u0430 \u0442\u0430\u0439\u043c\u0435\u0440\u0430     struct timespec sleep_period;     t_bool enable;      \/\/\u041f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0435 \u0434\u043b\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u0441 \u043f\u043e\u0442\u043e\u043a\u043e\u043c     pthread_t tid;     t_bool terminate;      \/\/\u0422\u0435, \u0441 \u043a\u0435\u043c \u0432\u0437\u0430\u0438\u043c\u043e\u0434\u0435\u0439\u0441\u0442\u0432\u0443\u0435\u0442 \u043e\u0431\u044a\u0435\u043a\u0442 \u0442\u0430\u0439\u043c\u0435\u0440\u0430     t_stimer_events* listener;     void* parent;      \/* \u0411\u0435\u0437\u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0435 \u0442\u0430\u0439\u043c\u0435\u0440\u0430 \u0432 \u0440\u0435\u0436\u0438\u043c\u0435 \"\u0432\u044b\u043a\u043b\u044e\u0447\u0435\u043d\"     \u0431\u0443\u0434\u0435\u0442 \u0431\u043b\u043e\u043a\u0438\u0440\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u0447\u0435\u0440\u0435\u0437 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0443\u044e \u0443\u0441\u043b\u043e\u0432\u0438\u044f *\/     pthread_cond_t cond_active;     pthread_mutex_t cond_lock; };  void* execute_thread(void* arg) {     int status;      t_stimer* timer = (t_stimer*) arg;      do {         \/\/\u0411\u043b\u043e\u043a\u0438\u0440\u043e\u0432\u043a\u0430 \u043f\u043e\u0442\u043e\u043a\u0430 \u0447\u0435\u0440\u0435\u0437 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0443\u044e \u0443\u0441\u043b\u043e\u0432\u0438\u044f         pthread_mutex_lock(&amp;timer->cond_lock);             if(timer->enable == false){                 \/* \u0415\u0441\u043b\u0438 \u0442\u0430\u0439\u043c\u0435\u0440 \u0432\u044b\u043a\u043b\u044e\u0447\u0435\u043d, \u0442\u043e \u0437\u0430\u0441\u044b\u043f\u0430\u0435\u043c \u0438 \u0436\u0434\u0451\u043c \"\u0431\u0443\u0434\u0438\u043b\u044c\u043d\u0438\u043a\",                 \u0441\u0438\u0433\u043d\u0430\u043b \u0443\u0441\u043b\u043e\u0432\u0438\u044f \u0434\u0435\u0431\u043b\u043e\u043a\u0438\u0440\u043e\u0432\u043a\u0438. *\/                 pthread_cond_wait(&amp;timer->cond_active,&amp;timer->cond_lock);             }         pthread_mutex_unlock(&amp;timer->cond_lock);          \/* \u0415\u0441\u043b\u0438 nanosleep \u043d\u043e\u0440\u043c\u0430\u043b\u044c\u043d\u043e \u0434\u043e\u0441\u043f\u0430\u043b\u0430, \u0442\u043e \u043c\u043e\u0436\u043d\u043e \u0441\u0444\u043e\u0440\u043c\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0441\u043e\u0431\u044b\u0442\u0438\u0435,         \u0430 \u0434\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0441\u0442\u0430\u0442\u0443\u0441 *\/         status = nanosleep(&amp;timer->sleep_period, NULL);          if(timer->enable == true &amp;&amp; status == 0){             pthread_mutex_lock(&amp;mutex);                 timer->listener->on_time(timer);             pthread_mutex_unlock(&amp;mutex);         }     } while(timer->terminate == false); }  void signal_handler(int sig) {     \/*  \u041f\u0443\u0441\u0442\u043e\u0439 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a \u0441\u0438\u0433\u043d\u0430\u043b\u0430.     \u0424\u0430\u043a\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u0434\u0430\u043d\u043d\u0430\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u0437\u0434\u0435\u0441\u044c \u043d\u0443\u0436\u043d\u0430 \u0442\u043e\u043b\u044c \u0434\u043b\u044f     \u0442\u043e\u0433\u043e \u0447\u0442\u043e \u0431\u044b \u043f\u0435\u0440\u0435\u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u0442\u044c \u0440\u0435\u0430\u043a\u0446\u0438\u044e \u043f\u043e\u0442\u043e\u043a\u0430 \u043d\u0430 \u0441\u0438\u0433\u043d\u0430\u043b SIGUSR1.     \u041f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e \u0440\u0435\u0430\u043a\u0446\u0438\u044f \u043d\u0430 \u0441\u0438\u0433\u043d\u0430\u043b \u044d\u0442\u043e \"\u0437\u0430\u0432\u0435\u0440\u0448\u0435\u043d\u0438\u0435 \u0440\u0430\u0431\u043e\u0442\u044b\".     \u0421\u0438\u0433\u043d\u0430\u043b \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c \u0447\u0442\u043e\u0431\u044b \u043f\u0440\u0435\u0440\u0432\u0430\u0442\u044c \u0441\u043e\u043d nanosleep.*\/ }  t_stimer* stimer_create(void* parent, int* exception) {     int status;      t_stimer* new_stimer = malloc(sizeof(t_stimer));     if(new_stimer == NULL){         *exception = errno;         return NULL;     }      new_stimer->enable = false;     new_stimer->terminate = false;     new_stimer->sleep_period.tv_sec=1;     new_stimer->sleep_period.tv_nsec=0L;     new_stimer->parent = parent;      if(single_init == false) {        \/\/\u041f\u0435\u0440\u0435\u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u043c \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a        signal(SIGUSR1,signal_handler);         \/\/\u0418\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0438\u0440\u0443\u0435\u043c \u043e\u0431\u0449\u0438\u0439 \u043c\u044c\u044e\u0442\u0435\u043a\u0441        status = pthread_mutex_init(&amp;mutex,NULL);        if(0!=status) goto crash_object;        single_init = true;     }     status = pthread_mutex_init(&amp;new_stimer->cond_lock,NULL);     if(0!=status) goto crash_object;      status = pthread_create(&amp;new_stimer->tid,0,execute_thread,new_stimer);     if(0!=status){         pthread_mutex_destroy(&amp;new_stimer->cond_lock);         goto crash_object;     }     n_timers++;     return new_stimer;      crash_object: \/\/\u0417\u0434\u0435\u0441\u044c \u0441\u0432\u043e\u0440\u0430\u0447\u0438\u0432\u0430\u0435\u043c\u0441\u044f \u0435\u0441\u043b\u0438 \u0447\u0442\u043e-\u0442\u043e \u043f\u043e\u0448\u043b\u043e \u043d\u0435 \u0442\u0430\u043a.     if((0 == n_timers) &amp;&amp; (single_init == true)){         pthread_mutex_destroy(&amp;mutex);         single_init = false;     }     free(new_stimer);     *exception = status;     return NULL; }  void stimer_set_active(t_stimer* timer, t_bool enable) {      timer->enable = enable;     \/\/\u0411\u0443\u0434\u0438\u043c \u0442\u0430\u0439\u043c\u0435\u0440, \u0435\u0441\u043b\u0438 \u043e\u043d \u0441\u043f\u0438\u0442     pthread_mutex_lock(&amp;timer->cond_lock);     pthread_cond_signal(&amp;timer->cond_active);     pthread_mutex_unlock(&amp;timer->cond_lock);      \/\/\u041f\u0440\u0435\u0440\u044b\u0432\u0430\u0435\u043c \u0438 \u0441\u0431\u0440\u0430\u0441\u044b\u0432\u0430\u0435\u043c nanosleep     pthread_kill(timer->tid,SIGUSR1); }  void stimer_destroy(t_stimer* timer) {     if(n_timers > 0){         \/\/\u041e\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u0435\u043c \u0442\u0430\u0439\u043c\u0435\u0440         timer->terminate = true;         stimer_set_active(timer,false);         \/\/\u0416\u0434\u0435\u043c \u0437\u0430\u0432\u0435\u0440\u0448\u0435\u043d\u0438\u044f \u043f\u043e\u0442\u043e\u043a\u0430         pthread_join(timer->tid,NULL);         \/\/\u0414\u0430\u043b\u0435\u0435 \u0432\u0441\u0451 \u0447\u0438\u0441\u0442\u0438\u043c         pthread_mutex_destroy(&amp;timer->cond_lock);          free(timer);         timer = NULL;         n_timers--;         if(n_timers == 0){             pthread_mutex_destroy(&amp;mutex);             single_init = false;         }     } }   void stimer_set_interval(t_stimer* timer, int value) {     ldiv_t t = ldiv(value, 1000);     timer->sleep_period.tv_sec = t.quot;     timer->sleep_period.tv_nsec = t.rem * 1000000; }  t_bool stimer_get_active(t_stimer* timer) {     return timer->enable; }  void stimer_set_listener(t_stimer* timer, t_stimer_events* listener) {     timer->listener = listener; }  void stimer_set_parent(t_stimer* timer, void* parent) {     timer->parent = parent; }  void* stimer_get_parent(t_stimer* timer) {     return timer->parent; }<\/code><\/pre>\n<p>\u00a0\u00a0 \u041c\u043e\u0436\u0435\u0442 \u0438 \u043d\u0435 \u043c\u043d\u043e\u0433\u043e \u043f\u043e\u044f\u0441\u043d\u0435\u043d\u0438\u0439, \u043d\u043e \u0438\u0437 \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u0430 \u043a\u043e\u0434\u0430 \u0438 \u043a\u043e\u043c\u043c\u0435\u043d\u0442\u0430\u0440\u0438\u0435\u0432 \u0432\u0441\u0451 \u043d\u0430 \u043f\u0435\u0440\u0432\u044b\u0439 \u0432\u0437\u0433\u043b\u044f\u0434 \u0434\u043e\u043b\u0436\u043d\u043e \u0431\u044b\u0442\u044c \u043f\u043e\u043d\u044f\u0442\u043d\u043e. \u0421 \u0442\u0430\u0439\u043c\u0435\u0440\u043e\u043c \u043d\u0430\u0434\u0435\u044e\u0441\u044c \u0440\u0430\u0437\u043e\u0431\u0440\u0430\u043b\u0438\u0441\u044c.<\/p>\n<p>\u0424\u0430\u0439\u043b\u044b \u0441 \u0438\u0441\u0445\u043e\u0434\u043d\u044b\u043c \u043a\u043e\u0434\u043e\u043c \u043c\u043e\u0436\u043d\u043e \u0441\u043a\u0430\u0447\u0430\u0442\u044c \u043d\u0430 <a href=\"https:\/\/github.com\/fsdkm\/C\" rel=\"noopener noreferrer nofollow\">https:\/\/github.com\/fsdkm\/C<\/a>. \u0412\u0441\u0435 \u0434\u0430\u043b\u044c\u043d\u0435\u0439\u0448\u0438\u0435 &#171;\u043f\u043e\u0434\u0435\u043b\u043a\u0438&#187; \u044f \u0431\u0443\u0434\u0443 \u0432\u044b\u043a\u043b\u0430\u0434\u044b\u0432\u0430\u0442\u044c \u0432 \u0434\u0430\u043d\u043d\u0443\u044e \u043f\u0430\u043f\u043a\u0443.<\/p>\n<p>PS:\u00a0\u00a0\u00a0 \u00a0<\/p>\n<p>\u00a0\u00a0 \u00a0\u0421\u0435\u0442\u044c Ethernet \u0434\u0430\u0451\u0442 Internet. \u0414\u043b\u044f Support Online Connect \u043f\u043e\u0434\u0430\u0432\u0430\u0439.\u00a0<\/p>\n<p>\u00a0\u00a0 \u00a0\u041f\u043e\u044d\u0442\u043e\u043c\u0443 \u0434\u0430\u043b\u0435\u0435 \u0432 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0438\u0438 \u0441 \u043f\u0440\u0438\u043d\u044f\u0442\u044b\u043c \u0440\u0430\u043d\u0435\u0435 \u0448\u0430\u0431\u043b\u043e\u043d\u043e\u043c \u041e\u041e\u041f \u0445\u043e\u0447\u0443 \u00ab\u043f\u043e\u044e\u0437\u0430\u0442\u044c\u00bb Socket -\u044b. \u0410 \u043d\u0430\u0447\u043d\u0443 \u0441 \u043a\u043b\u0438\u0435\u043d\u0442\u0430 TCP.  <\/p>\n<p>&#8212;<\/p>\n<\/div>\n<\/div>\n<\/div>\n<p><!----><!----><\/div>\n<p><!----><!----><br \/> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/articles\/569392\/\"> https:\/\/habr.com\/ru\/articles\/569392\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<div><!--[--><!--]--><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<p>\u00a0\u00a0 \u00a0\u0412\u0440\u0435\u043c\u044f \u044d\u0442\u043e \u043e\u0434\u043d\u043e \u0438\u0437 \u0438\u0437\u043c\u0435\u0440\u0435\u043d\u0438\u0439 \u043e\u043a\u0440\u0443\u0436\u0430\u044e\u0449\u0435\u0433\u043e \u043d\u0430\u0441 \u043c\u0438\u0440\u0430, \u0430 \u043b\u044e\u0431\u0430\u044f \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u043c\u0430\u044f \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u044c \u0438\u043b\u0438 \u043d\u0430\u0445\u043e\u0434\u0438\u0442\u0441\u044f (\u0443\u0441\u043b\u043e\u0432\u043d\u043e) \u0432 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0438 \u043f\u043e\u043a\u043e\u044f, \u0438\u043b\u0438 \u0438\u0437\u043c\u0435\u043d\u044f\u0435\u0442 \u0441\u0432\u043e\u0451 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435 \u0432 \u0442\u0435\u0447\u0435\u043d\u0438\u0435 \u0432\u0440\u0435\u043c\u0435\u043d\u0438. \u0418, \u0435\u0441\u0442\u0435\u0441\u0442\u0432\u0435\u043d\u043d\u043e \u0435\u0441\u043b\u0438 \u043d\u0435\u0442 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u0438 \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u044f \u0432\u0440\u0435\u043c\u0435\u043d\u0438, \u0447\u0442\u043e-\u0442\u043e \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0435\u043d\u043d\u043e\u0435 \u0441\u0432\u0430\u0440\u0433\u0430\u043d\u0438\u0442\u044c \u043d\u0435 \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u0441\u044f. \u041f\u043e\u044d\u0442\u043e\u043c\u0443 \u043f\u0435\u0440\u0432\u043e\u0435, \u0447\u0442\u043e \u0434\u043e\u043b\u0436\u043d\u043e \u0431\u044b\u0442\u044c &#8212; \u044d\u0442\u043e \u0440\u0435\u0448\u0435\u043d\u0438\u0435 \u0432 \u0432\u0438\u0434\u0435 \u0442\u0430\u0439\u043c\u0435\u0440\u0430. <\/p>\n<p>    \u00a0\u00a0 \u00a0\u0414\u043b\u044f Linux \u0432 \u0421\u0438 \u0432 \u043d\u0430\u0441\u0442\u043e\u044f\u0449\u0435\u0435 \u0432\u0440\u0435\u043c\u044f \u0435\u0441\u0442\u044c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0438:<\/p>\n<p><strong>unsigned int sleep(unsigned int __seconds); <\/strong>,<\/p>\n<p>\u043e\u0431\u044a\u044f\u0432\u043b\u0435\u043d\u043d\u0430\u044f \u0432 \u0444\u0430\u0439\u043b\u0435 <strong>&lt;unistd.h><\/strong> \u0438 <\/p>\n<p><strong>    int nanosleep(const struct timespec *req, struct timespec *rem); ,<\/strong><\/p>\n<p>\u043e\u0431\u044a\u044f\u0432\u043b\u0435\u043d\u043d\u0430\u044f \u0432 \u0444\u0430\u0439\u043b\u0435 <strong>&lt;time.h><\/strong><\/p>\n<p>    \u00a0\u00a0 \u00a0\u041e\u0431\u0435 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u044e\u0442 \u043e\u0434\u043d\u0443 \u0437\u0430\u0434\u0430\u0447\u0443, \u043f\u0440\u0438\u043e\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u044e\u0442 \u0440\u0430\u0431\u043e\u0442\u0443 \u043f\u043e\u0442\u043e\u043a\u0430 \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u0431\u044b\u043b\u0430 \u0432\u044b\u0437\u0432\u0430\u043d\u0430 \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u043d\u0430 \u0437\u0430\u0434\u0430\u043d\u043d\u043e\u0435 \u0432\u0440\u0435\u043c\u044f, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u0441 \u0434\u0430\u043d\u043d\u044b\u043c\u0438 \u0444\u0443\u043d\u043a\u0446\u0438\u044f\u043c\u0438 \u043e\u0447\u0435\u0432\u0438\u0434\u043d\u044b\u043c \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043f\u0440\u043e\u0441\u0442\u043e\u0435 \u0440\u0435\u0448\u0435\u043d\u0438\u0435 (\u043a\u0430\u043a \u0433\u043e\u0432\u043e\u0440\u0438\u0442\u0441\u044f \u00ab\u0440\u0435\u0448\u0435\u043d\u0438\u0435 \u0432 \u043b\u043e\u0431\u00bb) \u0432\u044b\u0434\u0435\u043b\u0438\u0442\u044c \u0434\u043b\u044f \u0442\u0430\u0439\u043c\u0435\u0440\u0430 \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u044b\u0439 \u043f\u043e\u0442\u043e\u043a.<\/p>\n<p>    \u00a0\u00a0 \u00a0\u0415\u0441\u0442\u044c \u0435\u0449\u0451 \u0444\u0443\u043d\u043a\u0446\u0438\u044f <strong>clock_nanosleep()<\/strong>, \u043c\u043e\u0436\u043d\u043e \u0432\u043a\u043b\u044e\u0447\u0438\u0442\u044c \u0440\u0435\u0436\u0438\u043c\u044b <strong>SHED_FIFO<\/strong> \u0438\u043b\u0438 <strong>SCHED_RR<\/strong> \u0434\u043b\u044f \u0431\u043e\u043b\u0435\u0435 \u0442\u043e\u0447\u043d\u043e\u0439 \u0440\u0430\u0431\u043e\u0442\u044b, \u0432\u0441\u0451 \u044d\u0442\u043e \u043a\u043e\u043d\u0435\u0447\u043d\u043e \u0445\u043e\u0440\u043e\u0448\u043e, \u043d\u043e \u044f \u0440\u0435\u0448\u0438\u043b \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0438\u0442\u044c\u0441\u044f \u0442\u043e\u043b\u044c\u043a\u043e \u0432\u044b\u0448\u0435 \u0443\u043a\u0430\u0437\u0430\u043d\u043d\u044b\u043c\u0438.  <\/p>\n<p>    \u00a0\u00a0 \u00a0\u0422\u0430\u0439\u043c\u0435\u0440 \u0434\u043e\u043b\u0436\u0435\u043d \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u043e\u0432\u0430\u0442\u044c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c \u0442\u0440\u0435\u0431\u043e\u0432\u0430\u043d\u0438\u044f: \u0434\u043e\u043b\u0436\u0435\u043d \u043c\u0438\u043d\u0438\u043c\u0430\u043b\u044c\u043d\u043e \u043f\u043e\u0442\u0440\u0435\u0431\u043b\u044f\u0442\u044c \u0432\u044b\u0447\u0438\u0441\u043b\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0435 \u0440\u0435\u0441\u0443\u0440\u0441\u044b,  \u0434\u043e\u043b\u0436\u0435\u043d \u043c\u0433\u043d\u043e\u0432\u0435\u043d\u043d\u043e \u0432\u043a\u043b\u044e\u0447\u0430\u0442\u044c\u0441\u044f\/\u0432\u044b\u043a\u043b\u044e\u0447\u0430\u0442\u044c\u0441\u044f, \u043f\u0440\u0438 \u044d\u0442\u043e\u043c \u0441\u0431\u0440\u0430\u0441\u044b\u0432\u0430\u0442\u044c \u0441\u0432\u043e\u0451 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435 \u0438 \u043e\u0431\u044f\u0437\u0430\u0442\u0435\u043b\u044c\u043d\u043e \u0431\u044b\u0442\u044c \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u0442\u043e\u0447\u043d\u044b\u043c.  <\/p>\n<p>    \u00a0\u00a0 \u00a0\u0414\u043b\u044f \u043d\u0430\u0447\u0430\u043b\u0430 \u044f \u0440\u0430\u0437\u0431\u0435\u0440\u0443 \u043f\u0430\u0440\u0443 \u0440\u0435\u0448\u0435\u043d\u0438\u0439 \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043a\u043e\u043d\u0435\u0447\u043d\u043e \u0431\u0443\u0434\u0443\u0442 \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c, \u043e\u0442\u043c\u0435\u0447\u0443 \u0438\u0445 \u043f\u043b\u044e\u0441\u044b \u0438 \u043c\u0438\u043d\u0443\u0441\u044b, \u043d\u043e \u0442\u0430\u043a \u0434\u0435\u043b\u0430\u0442\u044c \u043d\u0435 \u043d\u0430\u0434\u043e! \u0410 \u0432 \u043a\u043e\u043d\u0446\u0435 \u043f\u043e\u043a\u0430\u0436\u0443 \u0440\u0435\u0448\u0435\u043d\u0438\u0435 \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u043c\u0435\u043d\u044f \u0432 \u043f\u0440\u0438\u043d\u0446\u0438\u043f\u0435 \u043f\u043e\u043b\u043d\u043e\u0441\u0442\u044c\u044e \u0443\u0434\u043e\u0432\u043b\u0435\u0442\u0432\u043e\u0440\u044f\u0435\u0442, \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u043d\u043e \u0432 \u0440\u0430\u043c\u043a\u0430\u0445 \u043f\u0440\u0430\u0432\u0438\u043b \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0451\u043d\u043d\u043e\u0433\u043e \u0440\u0430\u043d\u0435\u0435 \u0448\u0430\u0431\u043b\u043e\u043d\u0430 \u0438 \u043d\u0430\u0434\u0435\u044e\u0441\u044c \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u043e \u0432 \u0434\u0430\u043b\u044c\u043d\u0435\u0439\u0448\u0438\u0445 \u043f\u0440\u043e\u0435\u043a\u0442\u0430\u0445.    <\/p>\n<p>    \u00a0\u00a0 \u00a0\u0418 \u0442\u0430\u043a \u043f\u0435\u0440\u0432\u043e\u0435 \u0440\u0435\u0448\u0435\u043d\u0438\u0435, \u044d\u0442\u043e \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u043d\u043e\u0432\u043e\u0433\u043e \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440\u0430 \u0442\u0430\u0439\u043c\u0435\u0440\u0430 \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u0442\u044c \u043d\u043e\u0432\u044b\u0439 \u043f\u043e\u0442\u043e\u043a, \u0447\u0442\u043e \u043c\u043e\u0436\u0435\u0442 \u043a\u043e\u043c\u0443-\u0442\u043e \u043f\u043e\u043a\u0430\u0437\u0430\u0442\u044c\u0441\u044f \u043d\u0435 \u043e\u0447\u0435\u043d\u044c \u0445\u043e\u0440\u043e\u0448\u0435\u0439 \u0438\u0434\u0435\u0435\u0439, \u043d\u043e \u0435\u0441\u043b\u0438 \u043d\u043e\u0432\u044b\u0435 \u043f\u043e\u0442\u043e\u043a\u0438 \u0431\u0443\u0434\u0443\u0442 \u043f\u043e\u0447\u0442\u0438 \u0432\u0441\u0435\u0433\u0434\u0430 \u0441\u043f\u0430\u0442\u044c \u0438 \u043d\u0435 \u0442\u0440\u0430\u0442\u0438\u0442\u044c \u0432\u044b\u0447\u0438\u0441\u043b\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0435 \u0440\u0435\u0441\u0443\u0440\u0441\u044b, \u0442\u043e \u043d\u0430\u0432\u0435\u0440\u043d\u043e\u0435 \u0432 \u044d\u0442\u043e\u043c \u043d\u0435\u0442 \u043d\u0438\u0447\u0435\u0433\u043e \u043f\u043b\u043e\u0445\u043e\u0433\u043e. \u0410, \u0432\u0442\u043e\u0440\u043e\u0435 \u0440\u0435\u0448\u0435\u043d\u0438\u0435, \u044d\u0442\u043e \u0437\u0430\u0434\u0435\u0439\u0441\u0442\u0432\u043e\u0432\u0430\u0442\u044c \u0432\u0441\u0435\u0433\u043e \u043e\u0434\u0438\u043d \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0439 \u043f\u043e\u0442\u043e\u043a \u0434\u043b\u044f \u0432\u0441\u0435\u0445 \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440\u043e\u0432 \u0442\u0430\u0439\u043c\u0435\u0440\u0430.<\/p>\n<p>    \u00a0\u00a0 \u00a0\u0414\u043b\u044f Linux \u0432 \u0421\u0438 \u043d\u0430\u0431\u043e\u0440 \u0444\u0443\u043d\u043a\u0446\u0438\u0439 \u0438 \u0442\u0438\u043f\u043e\u0432 \u0434\u043b\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u0441 \u043f\u043e\u0442\u043e\u043a\u0430\u043c\u0438 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d \u0432 \u0444\u0430\u0439\u043b\u0435 <strong>&lt;pthread.h><\/strong>. \u041f\u0440\u0438 \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0446\u0438\u0438 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0442\u044c \u043a\u043b\u044e\u0447 <strong>-lpthread<\/strong>.  \u0421\u0438\u043d\u0445\u0440\u043e\u043d\u0438\u0437\u0430\u0446\u0438\u044f \u043f\u043e\u0442\u043e\u043a\u043e\u0432 (\u043f\u0440\u0438 \u0434\u043e\u0441\u0442\u0443\u043f\u0435 \u043a \u043e\u0431\u0449\u0435\u043c\u0443 \u0440\u0435\u0441\u0443\u0440\u0441\u0443) \u043c\u043e\u0436\u0435\u0442 \u043e\u0441\u0443\u0449\u0435\u0441\u0442\u0432\u043b\u044f\u0442\u044c\u0441\u044f \u043c\u044e\u0442\u0435\u043a\u0441\u0430\u043c\u0438 \u0438 \u0441\u0435\u043c\u0430\u0444\u043e\u0440\u0430\u043c\u0438. \u0418 \u0434\u043b\u044f \u043f\u0440\u0430\u043a\u0442\u0438\u0447\u0435\u0441\u043a\u043e\u0433\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u0432\u0441\u0451 \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u043f\u0440\u043e\u0441\u0442\u043e.<\/p>\n<p>    \u00a0\u00a0 \u00a0\u041d\u043e\u0432\u044b\u0439 \u043a\u043b\u0430\u0441\u0441 \u0442\u0430\u0439\u043c\u0435\u0440\u0430 \u044f \u0440\u0435\u0448\u0438\u043b \u043d\u0430\u0437\u0432\u0430\u0442\u044c <strong>stimer<\/strong>, \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0435\u043d\u043d\u043e \u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043e\u0447\u043d\u044b\u0439 \u0444\u0430\u0439\u043b <strong>stimer.h<\/strong> \u043f\u043e\u043b\u0443\u0447\u0438\u043b\u0441\u044f \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0433\u043e \u0432\u0438\u0434\u0430, \u0438 \u043e\u043d \u0431\u0443\u0434\u0435\u0442 \u043e\u0431\u0449\u0438\u0439 \u0434\u043b\u044f \u0432\u0441\u0435\u0445 \u0440\u0435\u0448\u0435\u043d\u0438\u0439:<\/p>\n<pre><code class=\"cpp\">#ifndef _STIMER_H_ #define _STIMER_H_  #include &lt;stdlib.h> #include \"sfuns.h\" \/\/\u0412 sfuns.h \u043f\u0440\u043e\u0441\u0442\u043e \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0451\u043d \u0442\u0438\u043f t_bool  \/\/\u0421\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0430 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u044e\u0449\u0430\u044f \u043d\u043e\u0432\u044b\u0439 \u043a\u043b\u0430\u0441\u0441 struct stimer; typedef struct stimer t_stimer;  \/\/\u0421\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0430 \u0441\u043e\u0431\u044b\u0442\u0438\u0439. typedef struct stimer_events {     void (*on_time)(t_stimer* timer);     void (*on_error)(t_stimer* timer, int* exception); } t_stimer_events;  \/\/\u041a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440\/\u0434\u0435\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440 t_stimer* stimer_create(void* parent, int* exception); void stimer_destroy(t_stimer* timer);  \/\/\u0418\u043d\u0442\u0435\u0440\u0432\u0430\u043b void stimer_set_interval(t_stimer* timer, int value);  \/\/\u0410\u043a\u0442\u0438\u0432\u0430\u0446\u0438\u044f\/\u0434\u0435\u0430\u043a\u0442\u0438\u0432\u0430\u0446\u0438\u044f \u0442\u0430\u0439\u043c\u0435\u0440\u0430 void stimer_set_active(t_stimer* timer, t_bool enable); t_bool stimer_get_active(t_stimer* timer);  \/\/\u0421\u043b\u0443\u0448\u0430\u0442\u0435\u043b\u044c \u0441\u043e\u0431\u044b\u0442\u0438\u044f void stimer_set_listener(t_stimer* timer, t_stimer_events* listener);  \/\/\u0424\u0430\u043c\u0438\u043b\u0438\u044f \u0440\u043e\u0434\u0438\u0442\u0435\u043b\u044f void stimer_set_parent(t_stimer* timer, void* parent); void* stimer_get_parent(t_stimer* timer);  #endif<\/code><\/pre>\n<p>\u0412 \u043e\u0441\u043d\u043e\u0432\u043d\u043e\u043c \u0444\u0430\u0439\u043b\u0435 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u044b (<strong>main.c<\/strong> \u0438 \u043e\u043d \u0442\u0430\u043a\u0436\u0435 \u0431\u0443\u0434\u0435\u0442 \u043e\u0431\u0449\u0438\u0439 \u0434\u043b\u044f \u0432\u0441\u0435\u0445 \u0440\u0435\u0448\u0435\u043d\u0438\u0439), \u0434\u043b\u044f \u043f\u0440\u0438\u043c\u0435\u0440\u0430, \u043f\u0440\u0430\u043a\u0442\u0438\u0447\u0435\u0441\u043a\u043e\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 \u0442\u0430\u0439\u043c\u0435\u0440\u0430 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c:<\/p>\n<pre><code class=\"cpp\">#include &lt;stdlib.h> #include &lt;stdio.h> #include &lt;time.h> #include &lt;unistd.h> #include &lt;termios.h>  #include \"sfuns.h\" #include \"stimer.h\"  \/\/\u041e\u0431\u044a\u044f\u0432\u043b\u0435\u043d\u0430 \u043f\u0430\u0440\u0430 \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440\u043e\u0432 \u0442\u0430\u0439\u043c\u0435\u0440\u0430 t_stimer* timer1;  t_stimer* timer2; \/\/\u0421\u043b\u0443\u0448\u0430\u0442\u0435\u043b\u044c \u0441\u043e\u0431\u044b\u0442\u0438\u0439 \u043e\u0442 \u0442\u0430\u0439\u043c\u0435\u0440\u0430 t_stimer_events listener;  \/\/\u0424\u0443\u043d\u043a\u0446\u0438\u0438 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u0441\u043e\u0431\u044b\u0442\u0438\u0439 void ontime_events(t_stimer* timer) {     time_t curent_time;     time(&amp;curent_time);      if(timer == timer1){         printf(\"Event timer 1 %s\",ctime(&amp;curent_time));     }     if(timer == timer2){         printf(\"Event timer 2 %s\",ctime(&amp;curent_time));     } }  void onerror_events(t_stimer* timer, int* exception) {     if(timer == timer1){         printf(\"Error timer 1 %d\\n\", *exception);     }     if(timer == timer2){         printf(\"Error timer 2 %d\\n\", *exception);     } }  int main(int args, char** argv) {     unsigned char key;     int err;      \/\/\u041f\u0440\u0438\u0441\u0432\u043e\u0435\u043d\u0438\u0435 \u0441\u043b\u0443\u0448\u0430\u0442\u0435\u043b\u044e \u0441\u043e\u0431\u044b\u0442\u0438\u0439 \u0435\u0433\u043e \u0444\u0443\u043d\u043a\u0446\u0438\u0439 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u043e\u0432     listener.on_time = ontime_events;     listener.on_error = onerror_events;      \/\/\u0418\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u0432 \u0442\u0430\u0439\u043c\u0435\u0440\u0430. \u0422.\u043a. \u0440\u043e\u0434\u0438\u0442\u0435\u043b\u044c \u043d\u0430\u043c \u0432     \/\/\u0434\u0430\u043d\u043d\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u043d\u0435 \u043d\u0443\u0436\u0435\u043d, \u0442\u043e \u043f\u0435\u0440\u0432\u044b\u043c \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u043c \u043f\u0438\u0448\u0435\u043c NULL      timer1 = stimer_create(NULL,&amp;err);     if(timer1 == NULL){         printf(\"Ceate timer1. Error number: %d\\n\",err);         return 0;     }     timer2 = stimer_create(NULL,&amp;err);     if(timer2 == NULL){         printf(\"Ceate timer2. Error number: %d\\n\",err);         stimer_destroy(timer1);         return 0;     }      \/\/\u0420\u0435\u0433\u0438\u0441\u0442\u0440\u0430\u0446\u0438\u044f \u0441\u043b\u0443\u0448\u0430\u0442\u0435\u043b\u044f     stimer_set_listener(timer1,&amp;listener);     stimer_set_listener(timer2,&amp;listener);      \/\/\u0423\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0430 \u043f\u0435\u0440\u0438\u043e\u0434\u0438\u0447\u043d\u043e\u0441\u0442\u0438 \u0440\u0430\u0431\u043e\u0442\u044b \u0442\u0430\u0439\u043c\u0435\u0440\u043e\u0432     \/\/\u0415\u0441\u043b\u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0432\u0430\u0442\u044c \u0444\u0443\u043d\u043a\u0446\u0438\u044e sleep, \u0442\u043e \u0438\u043d\u0442\u0435\u0440\u0432\u0430\u043b \u0431\u0443\u0434\u0435\u0442 \u0437\u0430\u0434\u0430\u0432\u0430\u0442\u044c\u0441\u044f \u0432 \u0441\u0435\u043a\u0443\u043d\u0434\u0430\u0445.     \/\/\u0414\u043b\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u0438 nanosleep, \u0432 \u043f\u0440\u0438\u043c\u0435\u0440\u0430\u0445, \u0438\u043d\u0442\u0435\u0440\u0432\u0430\u043b \u0431\u0443\u0434\u0435\u0442 \u0437\u0430\u0434\u0430\u0432\u0430\u0442\u044c\u0441\u044f \u0432 \u043c\u0438\u043b\u043b\u0438\u0441\u0435\u043a\u0443\u043d\u0434\u0430\u0445.     stimer_set_interval(timer1, 3000);     stimer_set_interval(timer2, 5000);      stimer_set_active(timer1, true);     stimer_set_active(timer2, true);      \/\/\u041e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0430 \u043a\u043b\u0430\u0432\u0438\u0430\u0442\u0443\u0440\u044b     do {         key = sgetch();         printf(\"key: %d\\n\",key);         if(key==49){ \/\/1             stimer_set_active(timer1, false);             printf(\"timer1 active false\\n\");         }         if(key==50){ \/\/2             stimer_set_active(timer1, true);             printf(\"timer1 active true\\n\");         }         if(key==51){ \/\/3             stimer_set_active(timer2, false);             printf(\"timer2 active false\\n\");         }         if(key==52){ \/\/4             stimer_set_active(timer2, true);             printf(\"timer2 active true\\n\");         }     } while (key!=27); \/\/ESC      stimer_destroy(timer1);     stimer_destroy(timer2);      return 0; }<\/code><\/pre>\n<p>\u041f\u0435\u0440\u0432\u043e\u0435 \u0440\u0435\u0448\u0435\u043d\u0438\u0435 \u043e\u043f\u0440\u043e\u0431\u043e\u0432\u0430\u043b \u043d\u0430 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 <strong>sleep().<\/strong>  \u041c\u0430\u043a\u0441\u0438\u043c\u0430\u043b\u044c\u043d\u0430\u044f \u0447\u0430\u0441\u0442\u043e\u0442\u0430 \u043e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u044f \u0434\u0430\u043d\u043d\u043e\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u043e\u0434\u043d\u0430 \u0441\u0435\u043a\u0443\u043d\u0434\u0430, \u0447\u0442\u043e \u043c\u043e\u0436\u0435\u0442  \u0431\u044b\u0442\u044c \u0438 \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u044b\u043c \u0434\u043b\u044f \u0440\u0435\u0448\u0435\u043d\u0438\u044f \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0451\u043d\u043d\u043e\u0433\u043e \u043a\u0440\u0443\u0433\u0430 \u0437\u0430\u0434\u0430\u0447, \u043d\u043e \u0445\u043e\u0442\u0435\u043b\u043e\u0441\u044c \u0431\u044b  \u0431\u043e\u043b\u044c\u0448\u0435\u0433\u043e, \u0438 \u0442\u0430\u043a \u0441\u043c. \u0438\u0441\u0445\u043e\u0434\u043d\u044b\u0439 \u0444\u0430\u0439\u043b \u0441 \u043a\u043e\u043c\u043c\u0435\u043d\u0442\u0430\u0440\u0438\u044f\u043c\u0438:<\/p>\n<pre><code class=\"cpp\">#include &lt;stdlib.h> #include &lt;unistd.h> #include &lt;errno.h> #include &lt;pthread.h>  #include \"sfuns.h\" #include \"stimer.h\"  \/\/\u0422.\u043a. \u0434\u043e\u0441\u0442\u0443\u043f \u0434\u043e \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u0430 \u0441\u043e\u0431\u044b\u0442\u0438\u0439 \u0432\u043e\u0437\u043c\u043e\u0436\u0435\u043d \u0438\u0437 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u0438\u0445 \u043f\u043e\u0442\u043e\u043a\u043e\u0432, \/\/\u0442\u043e \u0434\u043b\u044f \u0441\u0438\u043d\u0445\u0440\u043e\u043d\u0438\u0437\u0430\u0446\u0438\u0438 \u043f\u043e\u043d\u0430\u0434\u043e\u0431\u0438\u043b\u0441\u044f \u043c\u044e\u0442\u0435\u043a\u0441  static pthread_mutex_t mutex;  \/\/\u0414\u043b\u044f \u043e\u0434\u043d\u043e\u0440\u0430\u0437\u043e\u0432\u043e\u0439 \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u043c\u044c\u044e\u0442\u0435\u043a\u0441\u0430 \u0438 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u043f\u0430\u0442\u0435\u0440\u043d\u0430 \"\u043e\u0434\u0438\u043d\u043e\u0447\u043a\u0430\" \/\/\u043f\u0440\u043e\u0441\u0442\u043e \u0432\u0432\u0435\u043b \u043b\u043e\u043a\u0430\u043b\u044c\u043d\u0443\u044e \u0433\u043b\u043e\u0431\u0430\u043b\u044c\u043d\u0443\u044e \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0443\u044e  static t_bool single_init = false;  \/\/\u041f\u043e\u0434\u0441\u0447\u0451\u0442 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u0430 \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440\u043e\u0432 \u0442\u0430\u0439\u043c\u0435\u0440\u0430 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c \u0434\u043b\u044f \u0442\u043e\u0433\u043e,  \/\/\u0447\u0442\u043e \u0431\u044b \u0432 \u0434\u0435\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440\u0435 \u043f\u043e\u043d\u0438\u043c\u0430\u0442\u044c, \u0447\u0442\u043e \u0443 \u043d\u0430\u0441 \u0435\u0449\u0451 \u043a\u0442\u043e-\u0442\u043e \u043e\u0441\u0442\u0430\u043b\u0441\u044f \u0438\u043b\u0438 \u043d\u0435\u0442. static int n_timers = 0;  \/\/\u0421\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0430 \u043a\u043b\u0430\u0441\u0441\u0430 \u0441 \u043f\u0440\u0438\u0432\u0430\u0442\u043d\u044b\u043c\u0438 \u043f\u043e\u043b\u044f\u043c\u0438 struct stimer {     int interval;      \/\/\u041f\u0435\u0440\u0438\u043e\u0434\u0438\u0447\u043d\u043e\u0441\u0442\u044c \u0440\u0430\u0431\u043e\u0442\u044b     t_bool enable;     \/\/\u0421\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435 \u0430\u043a\u0442\u0438\u0432\u043d\u043e\u0441\u0442\u0438      pthread_t tid;     \/\/\u0418\u0434\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440 \u043f\u043e\u0442\u043e\u043a\u0430     t_stimer_events* listener; \/\/\u0421\u043b\u0443\u0448\u0430\u0442\u0435\u043b\u044c \u0441\u043e\u0431\u044b\u0442\u0438\u0439     void* parent;              \/\/\u0427\u044c\u0438\u0445 \u0440\u043e\u0434\u0430 \u0431\u0443\u0434\u0435\u0442 };  \/\/\u0424\u0443\u043a\u0446\u0438\u044f \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u043e\u0433\u043e \u043f\u043e\u0442\u043e\u043a\u0430 void* execute_thread(void* arg) {     \/\/\u041f\u0435\u0440\u0435\u0434\u0430\u0447\u0430 \u0443\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u044f \u043d\u0430 \u044d\u043a\u0437\u0435\u043c \u0441\u043e\u0437\u0434\u0430\u043d\u043d\u043e\u0433\u043e \u043e\u0431\u044a\u0435\u043a\u0442\u0430 \u0442\u0430\u0439\u043c\u0435\u0440\u0430     t_stimer* timer = (t_stimer*) arg;          \/\/\u0412\u043a\u043b\u044e\u0447\u0430\u0435\u0442 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u043d\u0435\u043c\u0435\u0434\u043b\u0435\u043d\u043d\u043e\u0433\u043e \u0437\u0430\u0432\u0435\u0440\u0448\u0435\u043d\u0438\u044f \u043f\u043e\u0442\u043e\u043a\u0430     pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL);      do {         \/\/\u041e\u0442\u043f\u0440\u0430\u0432\u043b\u044f\u0435\u0442 \u043f\u043e\u0442\u043e\u043a \u0432 \u0441\u043e\u043d \u043d\u0430 \u0437\u0430\u0434\u0430\u043d\u043d\u044b\u0439 \u0438\u043d\u0442\u0435\u0440\u0432\u0430\u043b (\u0432 \u0441\u0435\u043a\u0443\u043d\u0434\u0430\u0445)         sleep(timer->interval);                   \/\/\u0422\u0430\u043a \u043a\u0430\u043a \u0434\u043b\u044f \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u0441\u043e\u0431\u044b\u0442\u0438\u0439, \u0434\u043b\u044f \u0432\u0441\u0435\u0445 \u043f\u043e\u0442\u043e\u043a\u043e\u0432, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f          \/\/\u043e\u0434\u043d\u0430 \u0438 \u0442\u0430\u0436\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u044f, \u0442\u043e \u0434\u043e\u0441\u0442\u0443\u043f \u043a \u043d\u0435\u0439 \u0441\u0438\u043d\u0445\u0440\u043e\u043d\u0438\u0437\u0438\u0440\u0443\u0435\u043c \u043c\u044e\u0442\u0435\u043a\u0441\u043e\u043c         pthread_mutex_lock(&amp;mutex);         timer->listener->on_time(timer);         pthread_mutex_unlock(&amp;mutex);      \/\/\u0422\u0430\u043a \u043a\u0430\u043a \u043f\u043e\u0442\u043e\u043a \u043c\u043e\u0436\u0435\u0442 \u0437\u0430\u0432\u0435\u0440\u0448\u0430\u0442\u044c\u0441\u044f \u043d\u0435\u043c\u0435\u0434\u043b\u0435\u043d\u043d\u043e,     \/\/\u0442\u043e \u043a\u0430\u043a\u0438\u0445-\u0442\u043e \u0443\u0441\u043b\u043e\u0432\u0438\u0439 \u0434\u043b\u044f \u0432\u044b\u0445\u043e\u0434\u0430 \u0438\u0437 \u0446\u0438\u043a\u043b\u0430 \u043d\u0435 \u0442\u0440\u0435\u0431\u0443\u0435\u0442\u0441\u044f              } while(1);   }  \/\/\u0424\u0443\u043d\u043a\u0446\u0438\u044f \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440 t_stimer* stimer_create(void* parent, int* exception) {     int status;      \/\/\u0412\u044b\u0434\u0435\u043b\u044f\u0435\u043c \u043f\u0430\u043c\u044f\u0442\u044c \u043f\u043e\u0434 \u043d\u043e\u0432\u044b\u0439 \u043e\u0431\u044a\u0435\u043a\u0442     t_stimer* new_stimer = malloc(sizeof(t_stimer));     \/\/\u041f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u043c, \u0447\u0442\u043e \u0432\u0441\u0451 \u0437\u0430\u043c\u0435\u0447\u0430\u0442\u0435\u043b\u044c\u043d\u043e \u0438\u043b\u0438 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u043c\u0441\u044f \u0441 \u043a\u043e\u0434\u043e\u043c \u043e\u0448\u0438\u0431\u043a\u0438     if(new_stimer == NULL){         *exception = errno;         return NULL;     }       \/\/\u0418\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0438\u0440\u0443\u0435\u043c \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0435 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u044b-\u0442\u0430\u0439\u043c\u0435\u0440\u0430     new_stimer->enable = false;     new_stimer->interval = 1;     new_stimer->parent = parent;          n_timers++;          \/\/\u041e\u0434\u043d\u043e\u043a\u0440\u0430\u0442\u043d\u0430\u044f \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u043e\u0431\u0449\u0435\u0433\u043e \u043c\u044e\u0442\u0435\u043a\u0441\u0430     if(single_init == false) {        status = pthread_mutex_init(&amp;mutex,NULL);        if(0!=status){            free(new_stimer);            *exception = status;            return NULL;        }        single_init = true;          }          return new_stimer; }  \/\/\u0424\u0443\u043d\u043a\u0446\u0438\u044f \u0434\u0435\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440 void stimer_destroy(t_stimer* timer) {     if(n_timers > 0){         if(timer->enable == true){             pthread_cancel(timer->tid);             timer->enable = false;         }         free(timer);         timer = NULL;         n_timers--;         if(n_timers == 0){             pthread_mutex_destroy(&amp;mutex);             single_init = false;         }     } }  \/\/\u0412\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435 \u0438 \u0432\u044b\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435 \u0442\u0430\u0439\u043c\u0435\u0440\u0430 void stimer_set_active(t_stimer* timer, t_bool enable) {      int status;      if((timer->enable == false) &amp;&amp; (enable == true)){         status = pthread_create(&amp;timer->tid,0,execute_thread,timer);         if(0!=status){             timer->listener->on_error(timer,&amp;status);         }     }     if((timer->enable == true) &amp;&amp; (enable == false)){         status = pthread_cancel(timer->tid);         if(0!=status){             timer->listener->on_error(timer,&amp;status);         }     }     timer->enable = enable; } \/\/\u0412\u043e \u0432\u0440\u0435\u043c\u044f \u0432\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u044f \u0438 \u0432\u044b\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u044f \u0442\u0430\u0439\u043c\u0435\u0440\u0430 \u0441\u043e\u0437\u0434\u0430\u0451\u0442\u0441\u044f \u0438 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0435\u043d\u043d\u043e \/\/\u0443\u043d\u0438\u0447\u0442\u043e\u0436\u0430\u0435\u0442 \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0439 \u043f\u043e\u0442\u043e\u043a. \u041d\u0430 \u044d\u0442\u043e \u0442\u0440\u0430\u0442\u044f\u0442\u0441\u044f \u0440\u0435\u0441\u0443\u0440\u0441\u044b, \u0447\u0442\u043e \u043d\u0435<\/code><\/pre>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-395888","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/395888","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=395888"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/395888\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=395888"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=395888"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=395888"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}