DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 2 of 2

Thread: C++ Pthread Lock / Unlock in succession

Threaded View

  1. #1
    Join Date
    Jan 2008

    C++ Pthread Lock / Unlock in succession


    I have some software with a bunch o' threads trying to read / edit a std::vector. I then also have a continuous loop inside main()

    If I create a mutex but immediately lock it and then in the main loop do

    The other threads (which are also blocked by the mutex btw) do not unblock. They do however if I do...

    usleep(1); // could even be 0 and still works.
    Can anyone suggest a reason for this? Does usleep() (and I assume sleep() in Windows) do something to make all the other threads take priority?

    From my experience of this so far, this instant block/unblock makes for a pretty simple way of ensuring thread safety in an otherwise slightly complex design. I just want to make sure I am not kludging things too much :)

    Best Regards,

    Last edited by kpedersen; 07-12-2011 at 09:29 AM.

Similar Threads

  1. How to Unlock the system??
    By faaz in forum C++
    Replies: 1
    Last Post: 05-09-2006, 04:11 AM
  2. Determining state of CAPS LOCK and NUM LOCK
    By David Williams in forum .NET
    Replies: 1
    Last Post: 04-04-2002, 10:31 AM
  3. ADO, Lock, SQL Server 7 & Oracle8i
    By Saiful in forum VB Classic
    Replies: 1
    Last Post: 09-11-2001, 08:35 AM
  4. Turn Num Lock, Caps Lock keys on and off with VB6
    By Chris Huynh in forum VB Classic
    Replies: 2
    Last Post: 03-01-2001, 09:57 AM
  5. Turn Num Lock, Caps Lock keys on and off with VB6
    By Chris Huynh in forum VB Classic
    Replies: 0
    Last Post: 03-01-2001, 01:52 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center
Latest Articles
Questions? Contact us.
Web Development
Latest Tips
Open Source

   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center