{"id":6428,"date":"2014-04-18T05:21:46","date_gmt":"2014-04-18T05:21:46","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2014\/04\/18\/is-it-possible-to-set-affinity-with-sched_setaffinity-in-android-collection-of-common-programming-errors\/"},"modified":"2014-04-18T05:21:46","modified_gmt":"2014-04-18T05:21:46","slug":"is-it-possible-to-set-affinity-with-sched_setaffinity-in-android-collection-of-common-programming-errors","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2014\/04\/18\/is-it-possible-to-set-affinity-with-sched_setaffinity-in-android-collection-of-common-programming-errors\/","title":{"rendered":"Is it possible to set affinity with sched_setaffinity in Android?-Collection of common programming errors"},"content":{"rendered":"<p>The following code works well with NDK r5 or newer:<\/p>\n<pre><code>#include \n#include \nvoid setCurrentThreadAffinityMask(int mask)\n{\n    int err, syscallres;\n    pid_t pid = gettid();\n    syscallres = syscall(__NR_sched_setaffinity, pid, sizeof(mask), &amp;mask);\n    if (syscallres)\n    {\n        err = errno;\n        LOGE(\"Error in the syscall setaffinity: mask=%d=0x%x err=%d=0x%x\", mask, mask, err, err);\n    }\n}\n<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>The following code works well with NDK r5 or newer: #include #include void setCurrentThreadAffinityMask(int mask) { int err, syscallres; pid_t pid = gettid(); syscallres = syscall(__NR_sched_setaffinity, pid, sizeof(mask), &amp;mask); if (syscallres) { err = errno; LOGE(&#8220;Error in the syscall setaffinity: mask=%d=0x%x err=%d=0x%x&#8221;, mask, mask, err, err); } }<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-6428","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/6428","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/comments?post=6428"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/6428\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=6428"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=6428"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=6428"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}