- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
<分区>
我编写了一个辅助函数,旨在将节点添加到链表中。这是要通过以下部分完成的位置。
tcb_add(running,temp);
该段应该为运行增加温度。这是我的函数代码。
void tcb_add(tcb_t *first, tcb_t *second) { //fix
if (first == NULL) {
first = second;
} else {
while (first->next != NULL) {
first = first->next;
}
first->next = second;
}
}
如果不使用行 tcb_add(running,temp);
我只是说 running = temp
它有效。但对于我代码的其他部分,我希望拥有该功能,因为它只是那么简单,因为 temp
是第一个添加的节点。任何帮助将不胜感激。
当然还有更多代码,但我相信我已将问题隔离开来。
这是我调用 tcb_add(running,temp);
时 Valgrind 的输出,但请记住,当我改为说 running = temp
时,该段有效。
==30628== Memcheck, a memory error detector
==30628== Copyright (C) 2002-2015, and GNU GPL'd, by Julian Seward et al.
==30628== Using Valgrind-3.11.0 and LibVEX; rerun with -h for copyright info
==30628== Command: ./test00
==30628==
==30628== Invalid read of size 8
==30628== at 0x400930: t_create (t_lib.c:42)
==30628== by 0x4007F9: main (test00.c:25)
==30628== Address 0x8 is not stack'd, malloc'd or (recently) free'd
==30628==
==30628==
==30628== Process terminating with default action of signal 11 (SIGSEGV)
==30628== Access not within mapped region at address 0x8
==30628== at 0x400930: t_create (t_lib.c:42)
==30628== by 0x4007F9: main (test00.c:25)
==30628== If you believe this happened as a result of a stack
==30628== overflow in your program's main thread (unlikely but
==30628== possible), you can try to increase the size of the
==30628== main thread stack using the --main-stacksize= flag.
==30628== The main thread stack size used in this run was 8388608.
==30628==
==30628== HEAP SUMMARY:
==30628== in use at exit: 67,432 bytes in 4 blocks
==30628== total heap usage: 4 allocs, 0 frees, 67,432 bytes allocated
==30628==
==30628== LEAK SUMMARY:
==30628== definitely lost: 24 bytes in 1 blocks
==30628== indirectly lost: 936 bytes in 1 blocks
==30628== possibly lost: 0 bytes in 0 blocks
==30628== still reachable: 66,472 bytes in 2 blocks
==30628== suppressed: 0 bytes in 0 blocks
==30628== Rerun with --leak-check=full to see details of leaked memory
==30628==
==30628== For counts of detected and suppressed errors, rerun with: -v
==30628== ERROR SUMMARY: 1 errors from 1 contexts (suppressed: 0 from 0)
Segmentation fault (core dumped)
变量running定义如下:
tcb_t *running;
tcb_t *ready;
这是根据结构:
struct tcb_t {
int thread_id;
int thread_priority;
ucontext_t *thread_context;
struct tcb_t *next;
}; typedef struct tcb_t tcb_t;
正如所问的,这是我的 t_create 函数:
int t_create(void (*fct)(int), int id, int pri) {
size_t sz = 0x10000;
ucontext_t *uc;
uc = (ucontext_t *)malloc(sizeof(ucontext_t));
getcontext(uc);
uc->uc_stack.ss_sp = malloc(sz); /* new statement */
uc->uc_stack.ss_size = sz;
uc->uc_stack.ss_flags = 0;
uc->uc_link = running->thread_context;
makecontext(uc, (void (*)(void))fct, 1, id);
tcb_t *new_tcb = malloc(sizeof(tcb_t));
new_tcb->thread_context = uc;
new_tcb->thread_id = id;
new_tcb->thread_priority = pri;
new_tcb->next = NULL;
tcb_t *tmp = ready;
if (tmp == NULL) // I would like to replace this portion with tcb_add()
ready = new_tcb;
else {
while (tmp->next != NULL) {
tmp = tmp->next;
}
tmp->next = new_tcb;// To here
}
还要进一步解释,虽然 valgrind 报告提到 t_create 这是我认为问题发生的地方。
void t_init() {
tcb_t *temp = tcb_create();
temp->thread_context = (ucontext_t *) malloc(sizeof(ucontext_t));
temp->thread_id = 0;
temp->thread_priority = 0;
temp->next = NULL;
getcontext(temp->thread_context);
tcb_add(running,temp); //DOES NOT WORK
//running = temp; //WORKS
ready = NULL;
}
C语言sscanf()函数:从字符串中读取指定格式的数据 头文件: ?
最近,我有一个关于工作预评估的问题,即使查询了每个功能的工作原理,我也不知道如何解决。这是一个伪代码。 下面是一个名为foo()的函数,该函数将被传递一个值并返回一个值。如果将以下值传递给foo函数,
CStr 函数 返回表达式,该表达式已被转换为 String 子类型的 Variant。 CStr(expression) expression 参数是任意有效的表达式。 说明 通常,可以
CSng 函数 返回表达式,该表达式已被转换为 Single 子类型的 Variant。 CSng(expression) expression 参数是任意有效的表达式。 说明 通常,可
CreateObject 函数 创建并返回对 Automation 对象的引用。 CreateObject(servername.typename [, location]) 参数 serv
Cos 函数 返回某个角的余弦值。 Cos(number) number 参数可以是任何将某个角表示为弧度的有效数值表达式。 说明 Cos 函数取某个角并返回直角三角形两边的比值。此比值是
CLng 函数 返回表达式,此表达式已被转换为 Long 子类型的 Variant。 CLng(expression) expression 参数是任意有效的表达式。 说明 通常,您可以使
CInt 函数 返回表达式,此表达式已被转换为 Integer 子类型的 Variant。 CInt(expression) expression 参数是任意有效的表达式。 说明 通常,可
Chr 函数 返回与指定的 ANSI 字符代码相对应的字符。 Chr(charcode) charcode 参数是可以标识字符的数字。 说明 从 0 到 31 的数字表示标准的不可打印的
CDbl 函数 返回表达式,此表达式已被转换为 Double 子类型的 Variant。 CDbl(expression) expression 参数是任意有效的表达式。 说明 通常,您可
CDate 函数 返回表达式,此表达式已被转换为 Date 子类型的 Variant。 CDate(date) date 参数是任意有效的日期表达式。 说明 IsDate 函数用于判断 d
CCur 函数 返回表达式,此表达式已被转换为 Currency 子类型的 Variant。 CCur(expression) expression 参数是任意有效的表达式。 说明 通常,
CByte 函数 返回表达式,此表达式已被转换为 Byte 子类型的 Variant。 CByte(expression) expression 参数是任意有效的表达式。 说明 通常,可以
CBool 函数 返回表达式,此表达式已转换为 Boolean 子类型的 Variant。 CBool(expression) expression 是任意有效的表达式。 说明 如果 ex
Atn 函数 返回数值的反正切值。 Atn(number) number 参数可以是任意有效的数值表达式。 说明 Atn 函数计算直角三角形两个边的比值 (number) 并返回对应角的弧
Asc 函数 返回与字符串的第一个字母对应的 ANSI 字符代码。 Asc(string) string 参数是任意有效的字符串表达式。如果 string 参数未包含字符,则将发生运行时错误。
Array 函数 返回包含数组的 Variant。 Array(arglist) arglist 参数是赋给包含在 Variant 中的数组元素的值的列表(用逗号分隔)。如果没有指定此参数,则
Abs 函数 返回数字的绝对值。 Abs(number) number 参数可以是任意有效的数值表达式。如果 number 包含 Null,则返回 Null;如果是未初始化变量,则返回 0。
FormatPercent 函数 返回表达式,此表达式已被格式化为尾随有 % 符号的百分比(乘以 100 )。 FormatPercent(expression[,NumDigitsAfterD
FormatNumber 函数 返回表达式,此表达式已被格式化为数值。 FormatNumber( expression [,NumDigitsAfterDecimal [,Inc
我是一名优秀的程序员,十分优秀!