Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/multithreading/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
c和initgraph中的线程_C_Multithreading_Graphics - Fatal编程技术网

c和initgraph中的线程

c和initgraph中的线程,c,multithreading,graphics,C,Multithreading,Graphics,这是我做的一个程序,但我面临的问题是它没有任何输出。当我试着运行一个线程时,它运行得很好,否则就不行了。我试图直接在终端中输出它,它工作得很好,但是当我试图使用initgraph在窗口中输出时,它不工作 #include <stdio.h> #include <stdlib.h> #include <pthread.h> #include<graphics.h> struct myran { int x; int y; };

这是我做的一个程序,但我面临的问题是它没有任何输出。当我试着运行一个线程时,它运行得很好,否则就不行了。我试图直接在终端中输出它,它工作得很好,但是当我试图使用initgraph在窗口中输出时,它不工作

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

struct myran 
{
    int x;
    int y;
};

void *print_message_function( void *ptr );

main() 
{
    int gd=DETECT,gm=VGAMAX;
    initgraph(&gd,&gm,NULL);

    pthread_t thread1, thread2;
    const char *message1 = "Thread 1";
    const char *message2 = "Thread 2";
    int  iret1, iret2;
    struct myran a,b,c,d;
    a.x=10;
    a.y=10;
    b.x=20;
    b.y=20;
    /* Create independent threads each of which will execute function */

    iret1 = pthread_create( &thread1, NULL, print_message_function, (void*) &a);
    if(iret1)
    {
        fprintf(stderr,"Error - pthread_create() return code: %d\n",iret1);
        exit(EXIT_FAILURE);
    }

    iret2 = pthread_create( &thread2, NULL, print_message_function, (void*) &b);
    if(iret2)
    {
        fprintf(stderr,"Error - pthread_create() return code: %d\n",iret2);
        exit(EXIT_FAILURE);
    }

    printf("pthread_create() for thread 1 returns: %d\n",iret1);
    //printf("pthread_create() for thread 2 returns: %d\n",iret2);

    /* Wait till threads are complete before main continues. Unless we  */
    /* wait we run the risk of executing an exit which will terminate   */
    /* the process and all threads before the threads have completed.   */

    pthread_join( thread1, NULL);
    pthread_join( thread2, NULL); 

    while(!kbhit())
    ;
    closegraph();

    exit(EXIT_SUCCESS);
} 

void *print_message_function( void *ptr )
{

    struct myran *ss;
    ss=(struct myran *)ptr;
    int `enter code here`x1,y1,x,y;
    x1=ss->x;
    y1=ss->y;
    int i=0;
    for(i=0;i<5;i++)
        printf("%d \n", x1);
}

我想是libgraph。应该在标题中提到它,而不是initgraphIn。值得一问的是,libgraph是线程安全的吗?或者,您是否需要重新设计一个处理libgraph交互的线程,并且所有其他线程将其消息发布到队列或类似的东西中,以便该线程拾取?