{"id":4183,"date":"2022-12-20T17:39:39","date_gmt":"2022-12-20T20:39:39","guid":{"rendered":"http:\/\/lode.uno\/linux-man\/index.php\/2022\/12\/20\/sleep_on-man9\/"},"modified":"2022-12-20T17:39:39","modified_gmt":"2022-12-20T20:39:39","slug":"sleep_on-man9","status":"publish","type":"post","link":"https:\/\/lode.uno\/linux-man\/2022\/12\/20\/sleep_on-man9\/","title":{"rendered":"sleep_on (man9)"},"content":{"rendered":"<h1 align=\"center\">sleep_on<\/h1>\n<p> <a href=\"#NAME\">NAME<\/a><br \/> <a href=\"#SYNOPSIS\">SYNOPSIS<\/a><br \/> <a href=\"#DESCRIPTION\">DESCRIPTION<\/a><br \/> <a href=\"#RETURN VALUE\">RETURN VALUE<\/a><br \/> <a href=\"#AVAILABILITY\">AVAILABILITY<\/a><br \/> <a href=\"#SEE ALSO\">SEE ALSO<\/a><br \/> <a href=\"#AUTHOR\">AUTHOR<\/a><br \/> <a href=\"#BUGS\">BUGS<\/a> <\/p>\n<hr>\n<h2>NAME <a name=\"NAME\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\">sleep_on \u2212 synchronization using a condition variable<\/p>\n<h2>SYNOPSIS <a name=\"SYNOPSIS\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\"><b>#include <linux\/sched.h><\/b><\/p>\n<table width=\"100%\" border=\"0\" rules=\"none\" frame=\"void\" cellspacing=\"0\" cellpadding=\"0\">\n<tr valign=\"top\" align=\"left\">\n<td width=\"11%\"><\/td>\n<td width=\"66%\">\n<p style=\"margin-top: 1em\"><b>void sleep_on(struct\u00a0wait_queue**<\/b><i>condition<\/i><b>)<\/b><\/p>\n<\/td>\n<td width=\"23%\"> <\/td>\n<\/tr>\n<\/table>\n<h2>DESCRIPTION <a name=\"DESCRIPTION\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\">The <b>sleep_on<\/b> function provides a means for synchronizing between processes and with interrupt handlers. The <i>condition<\/i> parameter is a pointer to a pointer to the opaque wait_queue type. Initialize the condition variable to zero, then pass a pointer to it to the <b>sleep_on<\/b> function. The basic idea is as follows:<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">struct wait_queue*con = 0;<\/p>\n<table width=\"100%\" border=\"0\" rules=\"none\" frame=\"void\" cellspacing=\"0\" cellpadding=\"0\">\n<tr valign=\"top\" align=\"left\">\n<td width=\"8%\"><\/td>\n<td width=\"92%\">\n<p>[&#8230;]<\/p>\n<\/td>\n<\/tr>\n<\/table>\n<p style=\"margin-left:11%;\">sleep_on(&#038;con);<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">While a process is sleeping, it is fully interruptible, no matter what the cpu state when entering the function. The cpu state is restored on being awakened.<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">If a null(0) is passed to <b>sleep_on<\/b>, it returns immediately, without sleeping. This is a no-op.<\/p>\n<h2>RETURN VALUE <a name=\"RETURN VALUE\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\">The <b>sleep_on<\/b> function only returns when explicitly awakened.<\/p>\n<h2>AVAILABILITY <a name=\"AVAILABILITY\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\">Linux 1+<\/p>\n<h2>SEE ALSO <a name=\"SEE ALSO\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\"><b>wake_up<\/b>(9)<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\"><i>\/usr\/src\/linux\/kernel\/sched.c<\/i><\/p>\n<h2>AUTHOR <a name=\"AUTHOR\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\">Stephen Williams <steve@icarus.com><\/p>\n<h2>BUGS <a name=\"BUGS\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\">A call to <i>sleep_on(0)<\/i> seems like an interesting way to test for and momentarily allow interrupts, but that is not what happens.<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">The <b>sleep_on<\/b> function cannot be called by interrupt handlers.<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">The function is not atomic with the condition tests that the driver writer might include, so the code executing the <b>sleep_on<\/b> function is protected from interrupts. Failure to do so generally leads to race conditions.<\/p>\n<hr>\n","protected":false},"excerpt":{"rendered":"<p>  sleep_on \u2212 synchronization using a condition variable <\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1222],"tags":[1226,1223,1225,1263],"class_list":["post-4183","post","type-post","status-publish","format-standard","hentry","category-9-rutinas-del-nucleo","tag-1226","tag-kernel","tag-man9","tag-sleep_on"],"gutentor_comment":0,"_links":{"self":[{"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/posts\/4183","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/comments?post=4183"}],"version-history":[{"count":0,"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/posts\/4183\/revisions"}],"wp:attachment":[{"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/media?parent=4183"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/categories?post=4183"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/tags?post=4183"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}