在我的应用程序中,main函数调用一个函数 - f2,它产生了几个线程,应用程序工作正常.现在我试图在f2之前添加一个新函数f1来生成一个新线程.这个新线程在屏幕上打印一些内容,然后在while循环中进行休眠.我得到了一次打印,一段时间后应用程序终止.在从GDB调试时,我得到以下消息:
(gdb) Program received signal SIG34, Real-time event 34.Quit
(gdb) bt
#0 0x0fa97cc8 in __nanosleep_nocancel ()
from /export/home/disk4/omsn/401.03022010/montavista/pro/devkit/ppc/82xx/target/lib/tls/libc.so.6
#1 0x0fa97a50 in __sleep (seconds=0) at sleep.c:137
#2 0x10007098 in f2 (arg=0x204) at main.c:152
#3 0x0fd2197c in start_thread (arg=0x204) at pthread_create.c:256
#4 0x0fac853c in clone ()
at ../sysdeps/unix/sysv/linux/powerpc/powerpc32/clone.S:100 warning: Previous frame inner to this frame (corrupt stack?)
Run Code Online (Sandbox Code Playgroud)
代码片段:
main(){
f1(); /*New function added to spawn a new task*/
f2(); /*Existing function spawns several tasks*/
}
Run Code Online (Sandbox Code Playgroud)
有人可以告诉我什么是"信号SIG34,实时事件34"以及可能导致相同的原因.
以下是f1的详细信息:
int f1(){
pthread_t …Run Code Online (Sandbox Code Playgroud) 我正在尝试制作一个C#软件来读取有关CPU的信息并将其显示给用户(就像CPU-Z一样).我目前的问题是我找不到显示CPU频率的方法.
起初我尝试使用Win32_Processor类的简单方法.事实证明它非常有效,除非CPU超频(或低频).
然后,我发现我的注册表在 HKLM\HARDWARE\DESCRIPTION\System\CentralProcessor\0中包含CPU的"标准"时钟(即使超频).问题是在现代CPU中,当CPU不需要它的全功率时,核心乘法器正在减少,因此CPU频率也在变化,但是注册表中的值保持不变.
我的下一步是尝试使用RdTSC来实际计算CPU频率.我使用C++是因为如果方法正常,我可以将它嵌入到C#项目中.我在http://www.codeproject.com/Articles/7340/Get-the-Processor-Speed-in-two-simple-ways找到了下一个代码, 但问题是一样的:程序只给出了我的最大频率(比如在注册表值,1-2 Mhz的差异),它看起来像它加载CPU超过它应该(我甚至有CPU负载峰值).
#include "stdafx.h"
#include <windows.h>
#include <cstdlib>
#include "intrin.h"
#include <WinError.h>
#include <winnt.h>
float ProcSpeedCalc() {
#define RdTSC __asm _emit 0x0f __asm _emit 0x31
// variables for the clock-cycles:
__int64 cyclesStart = 0, cyclesStop = 0;
// variables for the High-Res Preformance Counter:
unsigned __int64 nCtr = 0, nFreq = 0, nCtrStop = 0;
// retrieve performance-counter frequency per second:
if(!QueryPerformanceFrequency((LARGE_INTEGER *) &nFreq))
return 0;
// retrieve …Run Code Online (Sandbox Code Playgroud) 我正在浏览一些gcc属性列表,我发现这个引起我注意的那个:
nothrow
The nothrow attribute is used to inform the compiler that a function cannot
throw an exception. For example, most functions in the standard C library can be
guaranteed not to throw an exception with the notable exceptions of qsort and
bsearch that take function pointer arguments. The nothrow attribute is not
implemented in GCC versions earlier than 3.3.
Run Code Online (Sandbox Code Playgroud)
C函数如何抛出异常?有人可以解释这个属性用于什么?
似乎有一个nothrow标签可用,但我发现那里似乎与C++有关std::nothrow.不确定这是否与我的特定问题有关.
我想迭代所有(至少16位)unicode字符并用C在屏幕上打印它们.
我知道有关于SO的相关问题,但它们并没有解决printfC中的问题,但这是我想要实现的,如果它毕竟是可能的.我认为应该可能有一个我不知道的技巧.
既然我想使用printf,我想到了这样的事情:
for (int i = 0x0000; i <= 0xffff; i++) {
//then somehow increment the string
char str[] = "\u25A1\n";
printf("%s", str);
char str[] = "\u25A2\n";
printf("%s", str);
char str[] = "\u25A3\n";
printf("%s", str);
...
}
Run Code Online (Sandbox Code Playgroud)
但是这里增加unicode代码点有点问题\u25A1.我知道它本身不可能,因为有些字符\u0000不可打印,编译器说不.但除此之外,我怎么能从十六进制0000增加到ffff并打印字符printf.
请考虑以下代码:
#include <iostream>
using namespace std;
class A
{
public:
virtual void f() = 0;
A(){f();}
};
void A::f() {
cout<<"A"<<endl;
}
class B:public A{
public:
void f(){cout<<"B"<<endl;}
};
int main()
{
B b;
}
Run Code Online (Sandbox Code Playgroud)
在这种情况下,我直接从构造函数中调用虚函数并获取编译器警告,其中显示:
warning:abstract virtual'virtual void A :: f()'从构造函数调用.
但它执行时没有终止并打印A.
如果我像这样包装函数的调用:
class A
{
public:
virtual void f() = 0;
A(){g();}
void g(){f();}
};
void A::f(){cout<<"A"<<endl;}
class B:public A{
public:
void f(){cout<<"B"<<endl;}
};
int main()
{
B b;
}
Run Code Online (Sandbox Code Playgroud)
编译器在编译期间不会输出任何警告,但会在运行时使用以下消息进行压缩:
pure virtual method called
terminate called without …Run Code Online (Sandbox Code Playgroud) 我正在尝试用 allegro5 在 C 中播放 wav 文件,我写了下面的代码:
#include <stdio.h>
#include <allegro5/allegro.h>
#include <allegro5/allegro_audio.h>
#include <allegro5/allegro_acodec.h>
int main(int argc, char **argv){
ALLEGRO_DISPLAY *display = NULL;
if (!al_init()){
fprintf(stderr, "failed to initialize allegro!\n");
return -1;
}
if (!al_install_audio()){
fprintf(stderr, "failed to initialize audio!\n");
return -1;
}
if (!al_init_acodec_addon()){
fprintf(stderr, "failed to initialize audio codecs!\n");
return -1;
}
if (!al_reserve_samples(1)){
fprintf(stderr, "failed to reserve samples!\n");
return -1;
}
al_install_audio();
al_init_acodec_addon();
ALLEGRO_SAMPLE *sample = al_load_sample("bomb.wav"); //sample always NULL
al_reserve_samples(1);
if (!sample){
printf("Audio clip sample …Run Code Online (Sandbox Code Playgroud) 好吧,所以我非常接近完成这个计划.我理解为什么我的程序没有采取行动,我能够解决它,但现在我正在努力检查获胜者.我意识到我的winGame()功能应该在某种程度上或者在while循环中结束游戏.但是,当我试图做一些调试来解决一些问题时,我意识到一些令人不安的事情.它总是说它是一个平局,即使它不应该是.这些是很小的事情,我很惭愧,不理解,我真的希望得到一些帮助,我可以解决它.另外,我知道如果有胜利的话,应该有一段时间或者做while循环来结束游戏.我只是不确定在哪里放,所以如果您有任何建议,请告诉我.
*请注意,在我的有效移动函数中有一个小数组,我打算将其作为一个静态const数组.我的get函数返回名称中的值(例如getIval()返回单元格对象的初始值),而我的set函数只是适当地赋值.
bool TicTacToe::validMove(char move){
char options[9] = { '1','2', '3', '4','5','6','7', '8','9' };
bool validate = false;
for ( int i = 0; i < 9; i++ ){
if ( move == options[i]){
validate = true;
}
}
return ( validate );
}
void TicTacToe::setMove( char move ){
for ( int i = 0; i < ROW; i++ ){
for ( int j = 0; j < COL; j++ ){
if ( board[i][j].getiVal() == move ){
board[i][j].setiVal( …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用 读取另一个进程的内存process_vm_readv()。
一旦我读取该值,应用程序就会自行关闭(它不会崩溃)。不知何故,应用程序检测到我正在使用系统调用并尝试读取其内存。
我正在使用 Linux 4.4 内核的基于 x86 的 Android 操作系统(7.0)上尝试此操作。
此功能高度未记录,任何有关此的信息都会有所帮助。
这是我的实际代码的精简版本。
#include <sys/uio.h>
size_t readMem()
{
struct iovec local[1];
struct iovec remote[1];
char buf1[1024*8];
ssize_t nread;
pid_t pid = 3627;
local[0].iov_base = buf1;
local[0].iov_len = sizeof(buf1);
remote[0].iov_base = _ADDR // i in the loop below
remote[0].iov_len = sizeof(buf1);
return process_vm_readv(pid, local, 2, remote, 1, 0);
}
Run Code Online (Sandbox Code Playgroud)
需要明确的是,这实际上是一个函数。我从一个循环中调用这个函数,该循环遍历进程的每个内存地址。
for(long int i=0x7000000;!found;i+=4090)
Run Code Online (Sandbox Code Playgroud) 我有几个数组:
const string a_strs[] = {"cr=1", "ag=2", "gnd=U", "prl=12", "av=123", "sz=345", "rc=6", "pc=12345"};
const string b_strs[] = {"cr=2", "sz=345", "ag=10", "gnd=M", "prl=11", "rc=6", "cp=34", "cv=54", "av=654", "ct=77", "pc=12345"};
Run Code Online (Sandbox Code Playgroud)
然后我需要解析'='然后将值放在结构中.(rc键映射到结构中的fc键),其形式为:
struct predict_cache_key {
pck() :
av_id(0),
sz_id(0),
cr_id(0),
cp_id(0),
cv_id(0),
ct_id(0),
fc(0),
gnd(0),
ag(0),
pc(0),
prl_id(0)
{ }
int av_id;
int sz_id;
int cr_id;
int cp_id;
int cv_id;
int ct_id;
int fc;
char gnd;
int ag;
int pc;
long prl_id;
};
Run Code Online (Sandbox Code Playgroud)
我遇到的问题是数组不是与struct字段顺序或顺序相同.因此,我需要检查每个,然后想出一个方案,将相同的结构放入结构中.
有什么帮助使用C或C++来解决上述问题?
我试图找出如何在C++ VS中创建位图文件.目前我已经接受了文件名并添加了".bmp"扩展名来创建文件.我想知道如何通过将文件变成不同的颜色或图案来改变文件的像素(例如像棋盘一样)这是我的功能,我相信我必须一次发送3个不同的字节为了建立像素的颜色.
void makeCheckerboardBMP(string fileName, int squaresize, int n) {
ofstream ofs;
ofs.open(fileName + ".bmp");
writeHeader(ofs, n, n);
for(int row = 0; row < n; row++) {
for(int col = 0; col < n; col++) {
if(col % 2 == 0) {
ofs << 0;
ofs << 0;
ofs << 0;
} else {
ofs << 255;
ofs << 255;
ofs << 255;
}
}
}
}
void writeHeader(ostream& out, int width, int height){
if (width % 4 != 0) …Run Code Online (Sandbox Code Playgroud) c ×6
c++ ×5
linux ×2
allegro ×1
allegro5 ×1
android ×1
audio ×1
bitmap ×1
bmp ×1
c# ×1
compilation ×1
exception ×1
gcc ×1
if-statement ×1
inheritance ×1
memory ×1
ofstream ×1
parsing ×1
printf ×1
pthreads ×1
pure-virtual ×1
signals ×1
unicode ×1
visual-c++ ×1