Advertisement

04.30.2008 at 06:02PM PDT, ID: 23367376
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

9.0

Synchronization question

Asked by CyrexCore2k in C Programming Language, C++ Programming Language

I've been trying to figure out when and where a context switch can occur. I thought I understood it but a program I wrote seems to be proving me wrong.

Here's the setup. I've declared a global unsigned int val and in my main method I give it the value 2097152. I also created a global volatile char called hold which I've set to false in the main method. I then create 10 threads and have them run the following function:

void * thread_work(void * parameters)
{
   while(hold) {}
   val = val / 2;
   return NULL;
}

As soon as all the threads are created main will set hold to some value that evaluates to false. (I did this because I didn't want any threads executing while I'm still creating the others.)

Here's my question, why am I consistently getting the result 2048? Shouldn't I be getting random power of 2 values between that and 1048576? I thought the code might execute something like this:

thread1 moves memory value into register
thread1 divides value (lets say it's the first one so 1048576)
*context switch*
thread2 moves memory value into register (still 2097152)
thread2 divides value (lets say it's the first one so 1048576)
thread2 moves register value back into memory
*context switch*
thread1 moves register value back into memory

Which would make the result 4096 at least... so why isn't this happening? What am I misunderstanding here?Start Free Trial
[+][-]04.30.2008 at 06:09PM PDT, ID: 21475810

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]04.30.2008 at 07:45PM PDT, ID: 21476240

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]04.30.2008 at 07:49PM PDT, ID: 21476263

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]04.30.2008 at 07:54PM PDT, ID: 21476273

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]04.30.2008 at 08:07PM PDT, ID: 21476302

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]04.30.2008 at 08:56PM PDT, ID: 21476430

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]05.01.2008 at 01:18AM PDT, ID: 21477090

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]05.01.2008 at 02:41AM PDT, ID: 21477355

Assisted solutions are selected by the member who asked the question as a comment that contributed to their question's solution.

Start your 30-day free trial to view this Assisted Solution or ask the Experts your question.

 
[+][-]05.01.2008 at 03:51AM PDT, ID: 21477574

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]05.01.2008 at 09:03AM PDT, ID: 21479904

View this solution now by starting your 30-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zones: C Programming Language, C++ Programming Language
Sign Up Now!
Solution Provided By: billtouch
Participating Experts: 4
Solution Grade: A
 
 
 
Loading Advertisement...
20081112-EE-VQP-44 / EE_QW_EXPERT_20070906