小编Ami*_*mar的帖子

在Linux上执行pthread

我开始在linux上进行pthread编程,在第一个程序中我完全搞糊涂了.以下是我正在运行的程序

#include <stdio.h>
#include <stdlib.h>
#include <pthread.h>

void *print_message_function( void *ptr );

int main(){
 pthread_t thread1, thread2;
 char *message1 = "Thread 1";
 char *message2 = "Thread 2";
 int  iret1, iret2;

/* Create independent threads each of which will execute function */

 iret1 = pthread_create( &thread1, NULL, print_message_function, (void*) message1);
 iret2 = pthread_create( &thread2, NULL, print_message_function, (void*) message2);

 /* Wait till threads are complete before main continues. Unless we  */
 /* wait we run the risk of executing an exit which …
Run Code Online (Sandbox Code Playgroud)

c linux pthreads

3
推荐指数
1
解决办法
5652
查看次数

为什么我的C程序会输出这个?

我试图解决两个预处理器相关的问题,但在这两个程序中,我得到的结果是我无法弄清楚如何.以下是我的计划:

#include<stdio.h>
#define SQUARE(x) x*x
int main()
{
float s=10,u=30 ,t=2,a;
a=2*(s-u*t)/SQUARE(t);
printf("Result:%f\n",a);
return 0;
}
Run Code Online (Sandbox Code Playgroud)

据我说,这个程序的输出应该是,-25.000但我得到了-100.000.

在第二个程序中:

#define FUN(i,j) i##j
int main()
{
int val1 = 10;
int val12 = 20;
clrscr();
printf("%d\n",FUN(val1,2));
getch();
}
Run Code Online (Sandbox Code Playgroud)

输出应该是,102但我得到20; 为什么会这样?

c string-concatenation stringification c-preprocessor

3
推荐指数
1
解决办法
1573
查看次数

与C中的赋值运算符的相关性混淆

众所周知,赋值运算符的关联性是从右到左,但如果我们从右到左但输出为1,则在给定代码中输出应为零.

 main()
 {
 int a=3,b=2;
 a=a==b==0;
 printf("%d",a);
 }
Run Code Online (Sandbox Code Playgroud)

如果我们通过权利letf,输出如何变为1?

如果我们从右到左,那么(b == 0)应首先评估并给出结果0然后表达式(a == 0)是Evaluated也给出0,最后a的值将为0.

c

3
推荐指数
1
解决办法
1059
查看次数

我们在哪里可以使用C中的函数指针,什么用于函数指针

就在最近,我在接受采访时被问到:我们在哪里可以使用C中的函数指针?什么函数指针返回.我说使用我们可以使用函数指针调用函数然后他问了一些例子,但我不能满足于他更多的例子.然后他问我什么函数指针返回.我告诉他这取决于函数指针的声明.

但我真的想知道C中函数指针的一些用法.

c

3
推荐指数
1
解决办法
1889
查看次数

如何使用&&和||评估这些fork()调用 C中的运营商?

我在C下面有一些使用fork()系统调用的代码,但我很困惑:如何
解决它的问题:

int main()
{
    fork();
    fork() || fork() && fork();
    fork();
    printf("ämit");
}
Run Code Online (Sandbox Code Playgroud)

fork() && fork() || fork(); 评估如下所示:

       fork()
      /      \
    0/        \>0
 || fork()     && fork()
     /\            /   \
    /  \         0/     \>0
   *    *     || fork()  *
                /   \
               *     *
Run Code Online (Sandbox Code Playgroud)

我需要同样的树fork() || fork() && fork().任何人都可以告诉我应该如何实现它?

c

3
推荐指数
1
解决办法
429
查看次数

我们可以在c中对类型变量进行类型转换

我在采访中被问到这个问题:

是否可以将枚举变量强制转换为其他类型?

我真的不知道该怎么回答.

c

3
推荐指数
1
解决办法
1万
查看次数

U-boot.bin和uImage.bin有什么区别

u-boot.bin和之间感到困惑uImage.bin.我想uImage.bin只是压缩版本,u-boot.bin它的大小应该小于u-boot.bin.但是在我的构建环境中,我发现的是u-boot.bin尺寸小于uImage.bin.

有谁能让我知道u-boot.binuImage.bin?之间有什么区别?

linux linux-kernel embedded-linux u-boot

3
推荐指数
1
解决办法
2万
查看次数

在PowerPc上解码此程序集内联代码段

我在PowerPc的内核源代码片段下面有这个代码片段

#define SPRN_IVOR32     0x210   /* Interrupt Vector Offset Register 32 */

unsigned long ivor[3];
ivor[0] = mfspr(SPRN_IVOR32);

#define __stringify_1(x)        #x
#define __stringify(x)          __stringify_1(x)

#define mfspr(rn)       ({unsigned long rval; \
                    asm volatile("mfspr %0," __stringify(rn) \
                            : "=r" (rval)); rval; })
Run Code Online (Sandbox Code Playgroud)

另外,上面的练习是关于在PowerPc中模拟MSR寄存器的位吗?

任何人都可以帮我确切地说我们在这里做了什么?

c assembly powerpc inline-assembly

3
推荐指数
1
解决办法
576
查看次数

读取具有中断属性的设备树节点

我有两个不同的设备树源的片段.

UART1: serial@ef600400 {
              device_type = "serial";
              compatible = "ns16550";
              reg = <0xef600400 8>;
              virtual-reg = <0xef600400>;
              clock-frequency = <0x00a8c000>;
              current-speed = <0>;
              interrupt-parent = <&UIC0>;
              interrupts = <1 4>;
                    };


serial0: serial@4500 {
                    cell-index = <0>;
                    device_type = "serial";
                    compatible = "ns16550";
                    reg = <0x4500 0x100>;
                    clock-frequency = <0>;
                    interrupts = <42 2>;
                    interrupt-parent = <&mpic>;
            };
Run Code Online (Sandbox Code Playgroud)

我想知道什么是中断= <1 4>; 中断= <42 2>; 代表?

我们从哪里得到<1 4>,<42 2>的值?

powerpc linux-device-driver linux-kernel device-tree

3
推荐指数
1
解决办法
3410
查看次数

通过VFIO分配设备的中断处理

我试图了解通过VFIO分配给VM(来宾KVM)的设备的中断处理的工作原理,但是没有任何线索?

假设我有一个通过VFIO直接分配给Guest VM的设备(设备直通),并且该设备有硬件中断吗?

接下来发生什么?

arm kvm linux-device-driver interrupt-handling vfio

3
推荐指数
1
解决办法
1576
查看次数