.\" -*- coding: UTF-8 -*- '\" t .\" Copyright, the authors of the Linux man-pages project .\" .\" SPDX-License-Identifier: Linux-man-pages-copyleft .\" .\"******************************************************************* .\" .\" This file was generated with po4a. Translate the source file. .\" .\"******************************************************************* .TH pthread_getattr_np 3 "25 سبتمبر 2025" "صفحات دليل لينكس 6.18" .SH الاسم pthread_getattr_np \- الحصول على سمات الخيط المُنشأ .SH المكتبة مكتبة مسالك POSIX (\fIlibpthread\fP،\ \fI\-lpthread\fP) .SH موجز .nf \fB#define _GNU_SOURCE\fP /* انظر feature_test_macros(7) */ \fB#include \fP .P \fBint pthread_getattr_np(pthread_t \fP\fIthread\fP\fB, pthread_attr_t *\fP\fIattr\fP\fB);\fP .fi .SH الوصف الدالة \fBpthread_getattr_np\fP() تُهيئ كائن سمات الخيط المشار إليه بواسطة \fIattr\fP بحيث يحتوي على قيم السمات الفعلية التي تصف الخيط الجاري \fIthread\fP. .P قد تختلف قيم السمات المُرجعة عن قيم السمات المُقابلة المُمررة في كائن \fIattr\fP الذي استُخدم لإنشاء الخيط باستخدام \fBpthread_create\fP(3). على وجه الخصوص، قد تختلف السمات التالية: .IP \[bu] 3 حالة الفصل، حيث قد يفصل الخيط القابل للانضمام نفسه بعد الإنشاء؛ .IP \[bu] حجم المكدس، والذي قد تُحاذيه التطبيقات إلى حد مناسب. .IP \[bu] وحجم الحارس، والذي قد تُقرّبه التطبيقات لأعلى إلى مضاعف حجم الصفحة، أو تتجاهله (أي تعامله كـ 0)، إذا كان التطبيق يخصص مكدسه الخاص. .P علاوة على ذلك، إذا لم تُضبط سمة عنوان المكدس في كائن سمات الخيط المستخدم لإنشاء الخيط، فإن كائن سمات الخيط المُعاد سيُبلغ عن عنوان المكدس الفعلي الذي اختارته التطبيقات للخيط. .P عندما لا يعود كائن سمات الخيط المُعاد بواسطة \fBpthread_getattr_np\fP() مطلوبًا، يجب تدميره باستخدام \fBpthread_attr_destroy\fP(3). .SH "قيمة الإرجاع" عند النجاح، تعيد هذه الدالة 0؛ وعند حدوث خطأ، تعيد رقم خطأ غير صفري. .SH الأخطاء .TP \fBENOMEM\fP .\" Can happen (but unlikely) while trying to allocate memory for cpuset ذاكرة غير كافية. .P بالإضافة إلى ذلك، إذا كان \fIthread\fP يشير إلى الخيط الرئيسي، فقد تفشل \fBpthread_getattr_np\fP() بسبب أخطاء من استدعاءات أساسية متنوعة: \fBfopen\fP(3)، إذا تعذر فتح \fI/proc/self/maps\fP؛ و \fBgetrlimit\fP(2)، إذا لم يكن حد المورد \fBRLIMIT_STACK\fP مدعومًا. .SH السمات للاطلاع على شرح للمصطلحات المستخدمة في هذا القسم، انظر \fBattributes\fP(7). .TS allbox; lbx lb lb l l l. الواجهة السمة القيمة T{ .na .nh \fBpthread_getattr_np\fP() T} سلامة الخيوط MT\-Safe .TE .SH المعايير جنو؛ ومن هنا جاءت اللاحقة "_np" (غير محمول) في الاسم. .SH التاريخ glibc 2.2.3. .SH أمثلة البرنامج أدناه يوضح استخدام \fBpthread_getattr_np\fP(). يُنشئ البرنامج خيطًا يستخدم بعد ذلك \fBpthread_getattr_np\fP() لاسترداد وعرض سمات حجم الحارس وعنوان المكدس وحجم المكدس الخاصة به. يمكن استخدام وسائط سطر الأوامر لضبط هذه السمات على قيم غير المبدئية عند إنشاء الخيط. جلسات الصدفة أدناه توضح استخدام البرنامج. .P في التشغيل الأول، على نظام x86\-32، يُنشأ خيط باستخدام السمات المبدئية: .P .in +4n .EX $\fB ulimit \-s\fP # No stack limit ==> default stack size is 2 MB unlimited $\fB ./a.out\fP Attributes of created thread: Guard size = 4096 bytes Stack address = 0x40196000 (EOS = 0x40397000) Stack size = 0x201000 (2101248) bytes .EE .in .P في التشغيل التالي، نرى أنه إذا حُدد حجم حارس، يُقرّب لأعلى إلى المضاعف التالي لحجم صفحة النظام (4096 بايت على x86\-32): .P .in +4n .EX $\fB ./a.out \-g 4097\fP Thread attributes object after initializations: Guard size = 4097 bytes Stack address = (nil) Stack size = 0x0 (0) bytes \& Attributes of created thread: Guard size = 8192 bytes Stack address = 0x40196000 (EOS = 0x40397000) Stack size = 0x201000 (2101248) bytes .EE .in .\".in +4n .\".nf .\"$ ./a.out \-s 0x8000 .\"Thread attributes object after initializations: .\" Guard size = 4096 bytes .\" Stack address = 0xffff8000 (EOS = (nil)) .\" Stack size = 0x8000 (32768) bytes .\" .\"Attributes of created thread: .\" Guard size = 4096 bytes .\" Stack address = 0x4001e000 (EOS = 0x40026000) .\" Stack size = 0x8000 (32768) bytes .\".fi .\".in .P في التشغيل الأخير، يخصص البرنامج يدويًا مكدسًا للخيط. في هذه الحالة، تُتجاهل سمة حجم الحارس. .P .in +4n .EX $\fB ./a.out \-g 4096 \-s 0x8000 \-a\fP Allocated thread stack at 0x804d000 \& Thread attributes object after initializations: Guard size = 4096 bytes Stack address = 0x804d000 (EOS = 0x8055000) Stack size = 0x8000 (32768) bytes \& Attributes of created thread: Guard size = 0 bytes Stack address = 0x804d000 (EOS = 0x8055000) Stack size = 0x8000 (32768) bytes .EE .in .SS "مصدر البرنامج" .\" SRC BEGIN (pthread_getattr_np.c) \& .EX #define _GNU_SOURCE /* To get pthread_getattr_np() declaration */ #include #include #include #include #include #include \& static void display_stack_related_attributes(pthread_attr_t *attr, char *prefix) { int s; size_t stack_size, guard_size; void *stack_addr; \& s = pthread_attr_getguardsize(attr, &guard_size); if (s != 0) errc(EXIT_FAILURE, s, "pthread_attr_getguardsize"); printf("%sGuard size = %zu bytes\[rs]n", prefix, guard_size); \& s = pthread_attr_getstack(attr, &stack_addr, &stack_size); if (s != 0) errc(EXIT_FAILURE, s, "pthread_attr_getstack"); printf("%sStack address = %p", prefix, stack_addr); if (stack_size > 0) printf(" (EOS = %p)", (char *) stack_addr + stack_size); printf("\[rs]n"); printf("%sStack size = %#zx (%zu) bytes\[rs]n", prefix, stack_size, stack_size); } \& static void display_thread_attributes(pthread_t thread, char *prefix) { int s; pthread_attr_t attr; \& s = pthread_getattr_np(thread, &attr); if (s != 0) errc(EXIT_FAILURE, s, "pthread_getattr_np"); \& display_stack_related_attributes(&attr, prefix); \& s = pthread_attr_destroy(&attr); if (s != 0) errc(EXIT_FAILURE, s, "pthread_attr_destroy"); } \& static void * /* Start function for thread we create */ thread_start(void *arg) { printf("Attributes of created thread:\[rs]n"); display_thread_attributes(pthread_self(), "\[rs]t"); \& exit(EXIT_SUCCESS); /* Terminate all threads */ } \& static void usage(char *pname, char *msg) { if (msg != NULL) fputs(msg, stderr); fprintf(stderr, "Usage: %s [\-s stack\-size [\-a]]" " [\-g guard\-size]\[rs]n", pname); fprintf(stderr, "\[rs]t\[rs]t\-a means program should allocate stack\[rs]n"); exit(EXIT_FAILURE); } \& static pthread_attr_t * /* Get thread attributes from command line */ get_thread_attributes_from_cl(int argc, char *argv[], pthread_attr_t *attrp) { int s, opt, allocate_stack; size_t stack_size, guard_size; void *stack_addr; pthread_attr_t *ret_attrp = NULL; /* Set to attrp if we initialize a thread attributes object */ allocate_stack = 0; stack_size = \-1; guard_size = \-1; \& while ((opt = getopt(argc, argv, "ag:s:")) != \-1) { switch (opt) { case \[aq]a\[aq]: allocate_stack = 1; break; case \[aq]g\[aq]: guard_size = strtoul(optarg, NULL, 0); break; case \[aq]s\[aq]: stack_size = strtoul(optarg, NULL, 0); break; default: usage(argv[0], NULL); } } \& if (allocate_stack && stack_size == \-1) usage(argv[0], "Specifying \-a without \-s makes no sense\[rs]n"); \& if (argc > optind) usage(argv[0], "Extraneous command\-line arguments\[rs]n"); \& if (stack_size != \-1 || guard_size > 0) { ret_attrp = attrp; \& s = pthread_attr_init(attrp); if (s != 0) errc(EXIT_FAILURE, s, "pthread_attr_init"); } \& if (stack_size != \-1) { if (!allocate_stack) { s = pthread_attr_setstacksize(attrp, stack_size); if (s != 0) errc(EXIT_FAILURE, s, "pthread_attr_setstacksize"); } else { s = posix_memalign(&stack_addr, sysconf(_SC_PAGESIZE), stack_size); if (s != 0) errc(EXIT_FAILURE, s, "posix_memalign"); printf("Allocated thread stack at %p\[rs]n\[rs]n", stack_addr); \& s = pthread_attr_setstack(attrp, stack_addr, stack_size); if (s != 0) errc(EXIT_FAILURE, s, "pthread_attr_setstacksize"); } } \& if (guard_size != \-1) { s = pthread_attr_setguardsize(attrp, guard_size); if (s != 0) errc(EXIT_FAILURE, s, "pthread_attr_setstacksize"); } \& return ret_attrp; } \& int main(int argc, char *argv[]) { int s; pthread_t thr; pthread_attr_t attr; pthread_attr_t *attrp = NULL; /* Set to &attr if we initialize a thread attributes object */ \& attrp = get_thread_attributes_from_cl(argc, argv, &attr); \& if (attrp != NULL) { printf("Thread attributes object after initializations:\[rs]n"); display_stack_related_attributes(attrp, "\[rs]t"); printf("\[rs]n"); } \& s = pthread_create(&thr, attrp, &thread_start, NULL); if (s != 0) errc(EXIT_FAILURE, s, "pthread_create"); \& if (attrp != NULL) { s = pthread_attr_destroy(attrp); if (s != 0) errc(EXIT_FAILURE, s, "pthread_attr_destroy"); } \& pause(); /* Terminates when other thread calls exit() */ } .EE .\" SRC END .SH "انظر أيضًا" .ad l .nh \fBpthread_attr_getaffinity_np\fP(3)، \fBpthread_attr_getdetachstate\fP(3)، \fBpthread_attr_getguardsize\fP(3)، \fBpthread_attr_getinheritsched\fP(3)، \fBpthread_attr_getschedparam\fP(3)، \fBpthread_attr_getschedpolicy\fP(3)، \fBpthread_attr_getscope\fP(3)، \fBpthread_attr_getstack\fP(3)، \fBpthread_attr_getstackaddr\fP(3)، \fBpthread_attr_getstacksize\fP(3)، \fBpthread_attr_init\fP(3)، \fBpthread_create\fP(3)، \fBpthreads\fP(7) .PP .SH ترجمة تُرجمت هذه الصفحة من الدليل بواسطة زايد السعيدي . .PP هذه الترجمة هي وثيقة مجانية؛ راجع .UR https://www.gnu.org/licenses/gpl-3.0.html رخصة جنو العامة الإصدار 3 .UE أو ما بعده للاطلاع على شروط حقوق النشر. لا توجد أي ضمانات. .PP إذا وجدت أي أخطاء في ترجمة صفحة الدليل هذه، يرجى إرسال بريد إلكتروني إلى قائمة بريد المترجمين: .MT kde-l10n-ar@kde.org .ME .