Results 1 to 11 of 11

Thread: syncroniation between RTlinux thread and QT

  1. #1
    Join Date
    Feb 2007
    Posts
    63
    Qt products
    Qt3
    Platforms
    Unix/X11

    Default syncroniation between RTlinux thread and QT

    hi,
    i am making a project in which i am using QT at the front end and RTLinux at the backhand. My application involve making a FIFO in RTLinux,creating a thread, writting Data into fifo in the thread and reading the data at qt end.For reading i have to make a thread in the QT & read the data there.
    but the problem is i am not able to make syncroniation between RTLinux and QT.
    i tried with semaphores but it did'nt worked.
    pl help me to solve the problem

    bye

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,018 Times in 4,794 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: syncroniation between RTlinux thread and QT

    What does "didn't work" mean in this situation?

  3. #3
    Join Date
    Feb 2007
    Posts
    63
    Qt products
    Qt3
    Platforms
    Unix/X11

    Default

    i mean the thread in the QT and RtLinux thread dosen't syncronise

    can we use semaphore to syncronise thread in QT and RTLINUX???????????
    Last edited by wysota; 1st February 2007 at 11:58.

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,018 Times in 4,794 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: syncroniation between RTlinux thread and QT

    Could we see a piece of code you tried? There is no reason for the synchronisation not to work.

  5. #5
    Join Date
    Feb 2007
    Posts
    63
    Qt products
    Qt3
    Platforms
    Unix/X11

    Default Re: syncroniation between RTlinux thread and QT

    i am sending my code of both back hand and front hand..............
    have a look at it.......
    bye
    Attached Files Attached Files

  6. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,018 Times in 4,794 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: syncroniation between RTlinux thread and QT

    Quote Originally Posted by raghvendramisra View Post
    i am sending my code of both back hand and front hand
    As a Word document? Why not in a text file?

    Your problem is that the semaphores in the backend are not the same semaphores you use in the frontend. The fact that they both applications use the same variable names doesn't mean those variables represent the same objects. You should make the semaphore accessible to all processes by putting it in a shared memory segment:

    Quote Originally Posted by sem_init manual
    If pshared is non-zero, then the semaphore is shared between processes,
    and should be located in a region of shared memory (see shm_open(3),
    mmap(2), and shmget(2)). (Since a child created by fork(2) inherits
    its parent's memory mappings, it can also access the semaphore.) Any
    process that can access the shared memory region can operate on the
    semaphore using sem_post(3), sem_wait(3), etc.

  7. #7
    Join Date
    Feb 2007
    Posts
    63
    Qt products
    Qt3
    Platforms
    Unix/X11

    Default Re: syncroniation between RTlinux thread and QT

    hi,
    i have tried ir by using shared mem. but bach hand is giving error.
    i am attaching the code. pl have a look at it .
    thanks
    bye
    Attached Files Attached Files

  8. #8
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,018 Times in 4,794 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: syncroniation between RTlinux thread and QT

    Qt Code:
    1. addr=mmap(0,5003,PROT_READ|PROT_WRITE,MAP_SHARED,id,0);
    2. *addr=&bin_sem1;
    To copy to clipboard, switch view to plain text mode 
    Are you sure this is what you want? I doubt that... You're assigning a pointer containing a local address of the semaphore to the content of the address returned by mmap.... What is that supose to do?

    I was thinking about using shmget and shmat... After attaching a shared memory segment , you'll probably have to create a semaphore and memcpy it to the shared segment, initialise it there and only then use it from the other process.

  9. #9
    Join Date
    Feb 2007
    Posts
    63
    Qt products
    Qt3
    Platforms
    Unix/X11

    Default Re: syncroniation between RTlinux thread and QT

    hi,
    actually my back hand is in RTLinux and it doesen't support shmget & shmat. because it is showing error when i included the sys/ipc.h & sys/sem.h header files.

    so i m using mmap for shared memory.


    i have redefined the code. now it is giving segmentation error.
    could u plz look at it ant tell wat can be the problem?????????
    thnx

    bye
    Attached Files Attached Files

  10. #10
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,018 Times in 4,794 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: syncroniation between RTlinux thread and QT

    Quote Originally Posted by raghvendramisra View Post
    because it is showing error when i included the sys/ipc.h & sys/sem.h header files.
    What error?

    so i m using mmap for shared memory.
    mmap() is for mapping files or devices into memory, it's not a shared memory component. I don't know if you'll be able to use it this way...

    i have redefined the code. now it is giving segmentation error.
    could u plz look at it ant tell wat can be the problem?????????
    Please either provide a minimal compilable example as an attachment or embed the code directly into your post using [code] tags.

    Where does the segfault occur? Could you provide a backtrace using gdb?

  11. #11
    Join Date
    Feb 2007
    Posts
    63
    Qt products
    Qt3
    Platforms
    Unix/X11

    Default Re: syncroniation between RTlinux thread and QT

    hi,
    actually when i included ipc.h and sem.h header files it showed that "No such file or Directory". beco RTLinux dosen't support these header files.

    so i used mmap. it is working but with problem.
    i am pasting a piece of my code and the o/p.
    actually front end and back hand are syncroniosed for some time and the the program hangs.

    pl look at it


    ///////////////////back hand/////////////////////////////////////

    addr1=(sem_t*)mmap(0,5003,PROT_READ|PROT_WRITE,MAP _SHARED,id1,0);
    addr2=(sem_t*)mmap(0,5003,PROT_READ|PROT_WRITE,MAP _SHARED,id2,0);

    rtl_clock_gettime( CLOCK_REALTIME, &next);



    while ( run )
    {
    timespec_add_ns( &next, TIME);

    rtl_clock_nanosleep( CLOCK_REALTIME, TIMER_ABSTIME,&next, NULL);

    printf("BUS 1");

    sem_wait(&addr1[0]);

    w = write(fd2,&ch,1);

    if(w==-1)
    {
    printf("not written");
    }

    sem_post(&addr2[0]);
    ret=read(fd1,&rec,1);
    if(ret)
    {
    if (rec =='s')
    {
    run=0;
    printf("s = %c\n",rec);
    close(fd1);
    close(fd2);
    }
    }


    }

    rtl_pthread_exit(NULL);
    return(0);
    }


    ///////////////////////////front hand/////////////////////


    bk_addr1=(sem_t*)mmap(0,5003,PROT_READ | PROT_WRITE,MAP_SHARED,id1,0);
    bk_addr2=(sem_t*)mmap(0,5003,PROT_READ | PROT_WRITE,MAP_SHARED,id2,0);

    fd2=open(FIFO_NAME2,O_RDONLY|O_NONBLOCK); //openinf fifo


    sem_post(&bk_addr1[0]);

    while(1)
    {
    sleep(1);
    sem_wait(&bk_addr2[0]);

    q=read(fd2,&key,sizeof(key));
    if(q==-1)
    {
    printf("not read\n");
    }

    printf(" read=%d ",q);
    printf(" char=%c\n",key);

    sem_post(&bk_addr1[0]);


    }
    munmap(bk_addr1,5003);
    munmap(bk_addr2,5003);
    close(id1);
    close(id2);
    fclose(fp1);
    }



    /////////////out put///////////////
    BUS 1 read=1 char=a
    BUS 1 read=1 char=a
    BUS 1 read=1 char=a
    BUS 1 read=1 char=a
    BUS 1 read=1 char=a
    BUS 1 read=1 char=a
    BUS 1 read=1 char=a
    BUS 1 read=1 char=a
    BUS 1 read=1 char=a
    BUS 1 read=1 char=a
    BUS 1 read=1 char=a
    BUS 1 read=1 char=a
    BUS 1 read=1 char=a
    BUS 1 read=1 char=a
    BUS 1 read=1 char=a
    BUS 1 read=1 char=a
    BUS 1 read=1 char=a
    BUS 1 read=1 char=a
    BUS 1 read=1 char=a
    BUS 1 read=1 char=a
    BUS 1 read=1 char=a
    BUS 1BUS 1 read=1 char=a
    Segmentation fault

Similar Threads

  1. Problem closing a QMainWindow in Qt4.2
    By ian in forum Qt Programming
    Replies: 11
    Last Post: 17th October 2006, 00:49
  2. simple thread layout question
    By mhoover in forum Qt Programming
    Replies: 1
    Last Post: 12th August 2006, 11:02
  3. Replies: 11
    Last Post: 7th July 2006, 13:09
  4. [QT4] QThread and printing a QList<QPixmap>
    By KShots in forum Qt Programming
    Replies: 3
    Last Post: 24th April 2006, 21:44
  5. Replies: 2
    Last Post: 6th January 2006, 21:15

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.