![]() |
![]() |
![]() |
![]() |
![]() |
This version of this document is no longer maintained. For the latest documentation, see http://www.qnx.com/developers/docs. |
Control a thread
#include <sys/neutrino.h> int ThreadCtl( int cmd, void * data ); int ThreadCtl_r( int cmd, void * data );
libc
Use the -l c option to qcc to link against this library. This library is usually included automatically.
These kernel calls allow you to make QNX-specific changes to a thread.
The ThreadCtl() and ThreadCtl_r() functions are identical except in the way they indicate errors. See the Returns section for details.
The following calls are defined:
The function sets data to a positive or negative number, indicating the previous state of the the alignment-fault handling.
new_name_len name_buf_len name_buf[1]
The name_buf is a continuous buffer that extends the structure that contains space for max(name_buf_len, new_name_len). If new_name_len is
The current thread name (or previous name if a new name is being set) is placed as a NULL-terminated string in the buffer pointed to by name_buf. The name returned has a maximum of name_buf_len bytes. No thread name is returned if name_buf_len is zero.
![]() |
This call was defined in the QNX Neutrino Core OS 6.3.2. |
![]() |
Threads created by the calling thread inherit the _NTO_TCTL_IO status. |
![]() |
This call was defined in the QNX Neutrino Core OS 6.3.2. |
![]() |
This call was defined in the QNX Neutrino Core OS 6.3.2. |
By default, a thread's runmask is set to all ones, which allows it to run on any available processor. A value of 0x01 would, for example, force the thread to only run on the first processor.
You can use _NTO_TCTL_RUNMASK to optimize the runtime performance of your system by, for example, relegating nonrealtime threads to a specific processor. In general, this shouldn't be necessary, since the QNX realtime scheduler always preempts a lower-priority thread immediately when a higher priority thread becomes ready.
The main effect of processor locking is the effectiveness of the CPU cache, since threads can be prevented from migrating.
![]() |
Threads created by the calling thread don't inherit the specified runmask. |
![]() |
This call was defined in the QNX Neutrino Core OS 6.3.2. |
![]() |
Threads created by the calling thread aren't frozen. |
These calls don't block.
The only difference between these functions is the way they indicate errors:
#include <sys/neutrino.h> #include <sys/syspage.h> #include <malloc.h> #include <stdio.h> int main(void) { int *rsizep, rsize, size_tot; unsigned *rmaskp, *inheritp; unsigned buf[8]; void *freep; /* * struct _thread_runmask is not * uniquely sized so we construct * our own. */ rsize = RMSK_SIZE(_syspage_ptr->num_cpu); size_tot = sizeof(*rsizep); size_tot += sizeof(*rmaskp) * rsize; size_tot += sizeof(*inheritp) * rsize; if (size_tot <= sizeof(buf)) { rsizep = buf; freep = NULL; } else if ((rsizep = freep = malloc(size_tot)) == NULL) { perror("malloc"); return 1; } memset(rsizep, 0x00, size_tot); *rsizep = rsize; rmaskp = (unsigned *)(rsizep + 1); inheritp = rmaskp + rsize; /* * Both masks set to 0 means get current * values without alteration. */ if (ThreadCtl(_NTO_TCTL_RUNMASK_GET_AND_SET_INHERIT, rsizep) == -1) { perror("_NTO_TCTL_RUNMASK_GET_AND_SET_INHERIT"); free(freep); return 1; } /* * Restrict our inherit mask to the last cpu, leave * runmask unaltered. */ memset(rsizep, 0x00, size_tot); *rsizep = rsize; RMSK_SET(_syspage_ptr->num_cpu - 1, inheritp); if (ThreadCtl(_NTO_TCTL_RUNMASK_GET_AND_SET_INHERIT, rsizep) == -1) { perror("_NTO_TCTL_RUNMASK_GET_AND_SET_INHERIT"); free(freep); return 1; } free(freep); return 0; }
Safety: | |
---|---|
Cancellation point | No |
Interrupt handler | No |
Signal handler | Yes |
Thread | Yes |
InterruptDisable(), InterruptEnable(), InterruptMask(), InterruptUnmask()
![]() |
![]() |
![]() |
![]() |