CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6
  1. #1
    Join Date
    May 2002
    Location
    Germany
    Posts
    451

    Something similar to WaitForSingleObject in unix/linux

    Hello,

    What I need to make is a thread what suspends itself and restarts on ocassions when some events happen or so. I was originally wondering to use the WaitForSingleObject inside the thread with an infinite wait loop until event happends, but no idea about unix/linux. Could anybody please tell me how to do this?

  2. #2
    Join Date
    Sep 2002
    Location
    Belarus - Tirol, Austria
    Posts
    647
    Hi, there are some code I wrote for usage...
    It can help U

    I put 4 source files in one, because I could attach only one here... but I hope U can decide this .

    There are 2 mechanizms here:
    1) U can use CEvent object to emulate a waitnig process.
    2) There are many sync win functions (with the same name like in win api) but with internal part for linux (find WaitForSingleObject()).
    Attached Files Attached Files
    Last edited by dimm_coder; April 30th, 2003 at 03:45 AM.
    "UNIX is simple; it just takes a genius to understand its simplicity!"

  3. #3
    Join Date
    Apr 2003
    Location
    Morelia, Mexico
    Posts
    40
    Research about semaphores.

    I've used them with parent and child process, not sure about their behaviour with threads.

    semget(), semctl() and semfree() (not sure about the last one)
    int i;main(){for(;i["]<i;++i){--i;}"];read('-'-'-',i+++"hell\
    o, world!\n",'/'/'/'));}read(j,i,p){write(j/p+p,i---j,i/i);}

  4. #4
    Join Date
    Nov 2002
    Location
    Foggy California
    Posts
    1,245
    You can use sem_init(), sem_wait(), sem_trywait(), and sem_destroy().

    - Kevin

  5. #5
    Join Date
    May 2002
    Location
    Germany
    Posts
    451
    Hello,

    Today I started to use this and as a feedback, to dimm_coder: great job

  6. #6
    Join Date
    Sep 2002
    Location
    Belarus - Tirol, Austria
    Posts
    647
    I am glad that some code I wrote for own purposes can help someone else
    "UNIX is simple; it just takes a genius to understand its simplicity!"

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured